By which I am talking about "rebasing" within the dictionary, instead of git definition...

I've got a large, lengthy running Rails project which has about 250 migrations, it's obtaining a touch unwieldy to handle many of these.

Nevertheless, I actually do require a base by which to purge and rebuild my database when running tests. Therefore the data found in these is essential.

Does anyone have methods for say, dumping the schema in a set point - archiving off all of the old migrations and beginning anew with new migrations.

Clearly I'm able to use rake schema:dump - however , I want wherein db:migrate will load the schema first after which start running the relaxation from the migrations.

I must keep using migrations as they are very helpful in development, however, there is no way I am returning and editing a migration from 2007 therefore it appears silly to help keep it.

Generally, you don't have to cleanup old migrations. If you are running db:migrate on your own (no existing db), Rails uses db/schema.rb to produce the tables rather than running every migration. Otherwise, it only runs the migrations needed to upgrade in the current schema towards the latest.

Should you still wish to mix migrations up to and including given point into just one, you could attempt to:

  • migrate on your own as much as the specific schema using rake db:migrate VERSION=xxx
  • dump the schema using rake db:schema:dump
  • take away the migrations right from the start as much as version xxx and make up a single new migration while using items in db/schema.rb (put create_table and add_index claims in to the self.up approach to the brand new migration).

Make certain to select among the old migration version amounts for the aggregated new migration otherwise, Rails would attempt to apply that migration in your production server (which may wipe your existing data, because the create_table claims use :force⇒true).

Anyway, I wouldn't recommend to get this done since Rails usually handles migrations well itself. But when you'll still wish to, make certain to make sure everything and check out in your area first before you decide to risk data loss in your production server.