views:

12

answers:

1

This is a rails question about migration versions

So i have a few migrations already existing. i.e. in my db/migrate/ folder i have some files like this:

  • 1_add_products.rb
  • 2_add_customers.rb
  • 3_add_addresses.rb
  • 4_add_tags.rb

and i've ran "rake db:migrate" so the current version is 4. I want to go back to version 2 permanently and start branching from there. So i did "rake db:migrate VERSION=2" and this reverted the changes correctly to reflect version 2. However, whenever i run "rake db:migrate" now, it runs all 4 of the migrations and puts me back at version 4.

Is there a way to permanently go back to one revision and then start branching newly from there? Can i just simply delete migration 3 & 4 after i roll back to version 2 ??

The reason I ask is because after i roll back to version 2, i need to add new migrations and run "rake db:migrate" and i definitely do not want migration 3 and migration 4 to be included.

A: 

Deleting should work just fine. Just make sure that you have it rolled back EVERYWHERE (development, staging, production) otherwise you'll run into some weird problems.

And yes, definitely rollback THEN delete, otherwise your database will think it's in a state that doesn't actually exist.

Jamie Wong
In the future, I recommend you wait longer before accepting an answer. I'm fairly certain this is the correct answer, however it's always good to see if anyone disputes it.
Jamie Wong
oh, okay. i didn't know that hitting the check mark meant accepting answer, i thought it just meant "acknoledged/read". thanks.
dzt