Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rollback database migration on Heroku

I just deployed some code and database changes to Heroku and I would like to roll it back. I do have the releases add-on and was able to roll back the code but not the database. I didn't backup the database so I can't do a restore. I tried "heroku rake db:rollback" but it didn't do anything. Anyone knows?

like image 975
Bob Avatar asked Feb 09 '11 08:02

Bob


People also ask

How do I undo a db Migrate?

You can use db:migrate:undo , this command will revert the most recent migration. You can revert back to the initial state by undoing all migrations with the db:migrate:undo:all command.

How do I rollback a specific migration in Rails?

To check for status, run rails db:migrate:status . Then you'll have a good view of the migrations you want to remove. Then, run rails db:rollback to revert the changes one by one. After doing so, you can check the status again to be fully confident.


2 Answers

You have to run heroku rake db:rollback while the updated code that has the .down migration is deployed to Heroku. After that, you can rollback the code.

like image 181
yfeldblum Avatar answered Oct 05 '22 22:10

yfeldblum


db:rollback will rollback the last migration file that was executed - are you sure this hasn't been performed? If you're able to identify the number of migrations that you want to rollback for your deployment you can do

rake db:rollback STEP=3

which runs the down method in your last 3 migrations - this is of course if you've coded the down migration to revert exactly what was done in the up migration :)

like image 39
John Beynon Avatar answered Oct 05 '22 22:10

John Beynon