[Rails] How to Redo db:migrate to Heroku's Default PostgreSQL

Tadashi Shigeoka ·  Tue, October 4, 2011

I looked up how to forcibly redo db:migrate on Heroku, so here’s a memo.

First, Rails’ standard rake db:reset cannot be used on Heroku.

Instead, you can reset Heroku’s default postgres database using the pg:reset command.

$ heroku pg:reset --db SHARED_DATABASE_URL

After running the command, a prompt will appear for confirmation, so enter the app name to execute the reset.

By the way, SHARED_DATABASE_URL can be checked with the following command:

$ heroku console
Ruby console for codenote.heroku.com
>> ENV['DATABASE_URL']
=> "postgres://username:[email protected]/dbname"

・Reference: Heroku | Dev Center | PostgreSQL

There’s another way to redo db:migrate: by specifying VERSION=0, you can return to the initial state before the first db:migrate.

(This assumes that the migration file from the first db:migrate exists)

$ heroku rake db:migrate VERSION=0

Also, with db:migrate:redo, you can go back several steps (STEP=number of times).

$ heroku rake db:migrate:redo STEP=10

That’s all.

【Reference】

[Rails][Heroku] Herokuで強制的にdb:migrateをやり直す。その2 - mat_akiの日記 ([Rails][Heroku] Forcibly Redo db:migrate on Heroku. Part 2 - mat_aki’s Diary)

Herokuで強制的にdb:migrateをやり直す。 - このブログは証明できない。 (Forcibly Redo db:migrate on Heroku. - This Blog Cannot Be Proven.)

Ruby on Rails Guides: Migrations

That’s all from the Gemba.