user266003
user266003

Reputation:

Do undo for a migration

There is a migration which has been applied and commited to github. It contains a custom code, meaning it's to do "down". In fact, the method "down" is empty.I can delete a db and it's ok since there is not much the data in it.

Now I need to change it this migration, specifically, I need to change it totally. So I need to somehow undo it, commit to github and allow other members of our command apply it.

How do I do that?

Notice that is not a last migration, there were other ones also after this one.

Upvotes: 0

Views: 640

Answers (2)

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22296

You can create a new migration or change the that migration and before apply it do a rollback. Use VERSION as said by the docs:

rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).

rake db:migrate VERSION=x
change your migration file
git commit
rake db:migrate

Upvotes: 1

Narfanator
Narfanator

Reputation: 5803

I think your best bet is to write a new migration that performs the undo and push that. As I'm gathering, migrations are about changing an existing database, rather than creating a new one - this is why you have the changes in two places - migrations, and db/schema.rb - and some people actually suggest removing old migrations.

Upvotes: 2

Related Questions