sam ruditsky
sam ruditsky

Reputation: 25

Rails Migrations Convention

I've started working with rails recently and I have noticed that during development you can end up with a lot of migration files as your ideas change and your database with it. Is there a convention in rails to avoid accumulating a lot of migrations and deleting redundant ones (such as one migration adding a table and then the next deleting it)? Or, is it preferred to keep all your migrations and never delete them? Thanks.

Upvotes: 1

Views: 44

Answers (2)

sandeep ks
sandeep ks

Reputation: 11

The primary job of migration files is to alter the database schema. Deleting redundant ones (such as one migration adding a table and then the next deleting it) will not cause any problems and it free up some disk space and slug size.

Upvotes: 0

Rafayet Monon
Rafayet Monon

Reputation: 1179

If you are working on a team it is preferred and you always should keep all the migrations.

Suppose you push a migration to Git and later found out that it needs some change. So you revert and delete the migration and create a new one and push the new changes. It works well in your machine. But if somehow your previous faulty migrations are run by any of your team mate and he pull the new code he will have to run the new migrations which will break the applications in your teammates machine.

But if you are working solo and want to get a bit tidy then you can carefully delete migrations after reverting them (Not preferred).

Upvotes: 1

Related Questions