Best practices for managing databases in production

At my job we do everything on a staging server and usually with a copy of production data for that server. So we will drop the entire production database and transfer it to the staging server just to ensure we maintain data integrity. This is really the only way to ensure you know how a script will work at 100 records and how it will work at 1 million records or even 1 billion records. if the database is too big then we usually try to create a partial of it or simulate enough data to make it realistic. Ideally we test it enough to ensure we don’t screw things up in production.

Never roll back the database unless you can avoid it. Data loss is incredibly touchy for most users and even in minor apps will lose you users and or customers. I would usually create another rake task to fix the issue at hand, the other route is to use migrations/seeds in some combination to handle migrating data for you. There are some gems that will act like migrations for data. The one mentioned by @geoffharcourt is a decent one.

2 Likes