Question

So I've been working on this web app for a year now and I would like to compile to schema into ONE migration, that way my text editor loads faster, git working directory isn't so cluttered.

Search find will be faster.

Any my config/db won't be 4000px long.

Was it helpful?

Solution

One way to go is to take a blank database and run all the migrations. Now you've got all the template data which you can save to a yaml. The yaml plus the schema should be enough to bring the DB back without running any of your previously existing migrations.

However, other answers should mention an existing tool or gem for doing this.

OTHER TIPS

Remove the migration files once you've migrated your servers. If you ever want to start with a fresh deployment, run rake db:schema:load or rake db:setup. You shouldn't be re-running all your migrations as explained here.

You don't need to keep your migrations around forever, you are free to delete them as soon as you're sure you don't need them anymore. Just go into your db/migrate/ directory and delete the migrations that are older than, say, a couple months.

As long as all the migrations that you want to delete have been applied everywhere (i.e. development and production) then you don't need them anymore (unless you want to go backwards). Really, migrations aren't meant to be permanent files, they're just around to get you from A to B and then they're just baggage.

Given that none of the answers mention it, this is the gem that does the job: https://github.com/jalkoby/squasher

It basically reruns the migrations from scratch until the date you specify, and then loads the resulting db/schema.rb into an initial migration that replaces the old ones. It can also cleanup the schema_migrations table so you don't get those

up     <timestamp>  ********** NO FILE **********

entries when running rake db:migrate:status.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top