rails rolling back migration permanently then branching
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 file开发者_运维技巧s 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.
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.
精彩评论