Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to purge old Rails migration files?

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?

like image 936
Simone Carletti Avatar asked Nov 22 '10 18:11

Simone Carletti


People also ask

Should I delete old migrations?

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.

Can I delete migration files Rails?

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.


2 Answers

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 a db/archived_migrations folder or something like that. Once you do trim the size of your migrations folder, use the rake db:reset task to (re-)create your database from db/schema.rb and load the seeds into your current environment.

like image 157
user12121234 Avatar answered Sep 20 '22 20:09

user12121234


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.

like image 45
bryan thompson Avatar answered Sep 21 '22 20:09

bryan thompson