I have been running a big Rails application for over 2 years and, day by day, my ActiveRecord migration folder has been growing up to over 150 files.
There are very old models, no longer available in the application, still referenced in the migrations. I was thinking to remove them.
What do you think? Do you usually purge old migrations from your codebase?
You don't need to keep around your old migration files in a Rails app, because your database schema should be captured either in schema. rb or an equivalent SQL file that can be used to regenerate your schema. Migrations are not the authoritative source for your database schema. That role falls to either db/schema.
No, since Rails would not know how to delete it. It needs to call the self. down method defined on your migration to "downgrade" your database.
The Rails 4 Way page 177: Sebastian says...
A little-known fact is that you can remove old migration files (while still keeping newer ones) to keep the
db/migrate
folder to a manageable size. You can move the older migrations to adb/archived_migrations
folder or something like that. Once you do trim the size of your migrations folder, use therake db:reset
task to (re-)create your database fromdb/schema.rb
and load the seeds into your current environment.
Once I hit a major site release, I'll roll the migrations into one and start fresh. I feel dirty once the migration version numbers get up around 75.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With