Merge all migation files

Hi, My One of Rails Project started 2 years ago. Today I see there are many changes on database. Many Tables/ and table fields got added and many were removed as well. If I see my db/migration folder It has almost 200 files.

I wish to suggest a feature where by running a command like rake db:migrate:files could merge all files into table-wise. like if 20 tables are there It make new 20 migration cleaner way.

Please suggest!

This is what your schema.rb file is for.

The schema.rb file it is indeed for this. One thing we do at Shopify, is we have a db:migrate:rollup task, that delete the files older than 3 months that are on the schema.rb already. So we dont keep a huge folder of migrations. Not sure if that’s everyones use case tho.

At Toptal we do a similar thing, we periodically clean up old migrations with GitHub - jalkoby/squasher: Squasher - squash your old migrations in a single command. We delete all old ones and update one “initial migration”.