Search code examples
ruby-on-railsdatabase-migration

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.


Solution

  • 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).