dino d. wrote:
I no longer need a join table and want to drop it, but I want to be
able to recover if I’ve made a mistake. Is there an easy way to
capture the current state of the table and incorporate it into my
Also, is there a way to flatten my migrations to one master? Like, to
say, “take the current state of my tables and commit them to one
I use the annotate_models rake task (google it on the web) to keep my
model commented with the latest state of that table in the db. Your
“undo” on the down would be to simply create the table in its current
Flattening your migration depends on whether you’ve gone live or not.
Cool in dev as long as you comunicate with your team, risky/inadvisable
You can certainly move the net of all your migrations into a single one,
but you need to be sure your schema version matches your last migration.
I do this periodically in dev, along the lines of:
I have 28 migrations, and the schema is settled (for now).
rake db:migrate VERSION=0
combine/edit my migrations into to the 1, 5, or 16 I want (you wanted
just one, which is equally possible. IIRC, Danimal does this as well.)
Once you’re set with your 1 migration:
Schema version 1 now has all your tables in one shot.
If version 1 goes live, and you have users data in your DB, that
migration becomes sacrosanct. You shouldn’t ever alter that migration,
but can add new migrations on top of it in dev, and tinker with as you
want. When it’s time to produce your uber migration for version 2, in
dev, rake to version 1, edit/combine migrations 2 through whatever into
just migration 2, then rake up again.
That can be safely deployed to live on top of your 001 migration.