- Assuming you have multiple Heroku apps and Git remote like so:
development https://git.heroku.com/xxx.git (fetch)
development https://git.heroku.com/xxx.git (push)
origin [email protected]:xxx/xxx.git (fetch)
origin [email protected]:xxx/xxx.git (push)
production https://git.heroku.com/xxx.git (fetch)
production https://git.heroku.com/xxx.git (push)
staging https://git.heroku.com/xxx.git (fetch)
staging https://git.heroku.com/xxx.git (push)
- In this tutorial, I'm upgrading Hobby Basic plan to Standard 0 plan for my staging app.
- Start with:
$ cd into/the/rails/project
- Turn on Maintenance Mode for your Heroku app:
$ heroku maintenance:on -r staging
- Login as owner of the app by doing:
$ heroku login
- Provision new database:
$ heroku addons:create heroku-postgresql:standard-0 -r staging && heroku pg:wait -r staging
-
Check your Heroku web UI > app > Resources. You should see your new database with name pattern like this -
Heroku Postgres :: XXX
. Take the color after the::
and capitalize it. For example, I sawHeroku Postgres :: Amber
and I should useAMBER
in next step. -
Promote the new database to our Heroku app by taking the color from step 7 above and append it after
HEROKU_POSTGRESQL_
$ heroku pg:promote HEROKU_POSTGRESQL_AMBER -r staging
- Copy old database to new database:
$ heroku pg:copy HEROKU_POSTGRESQL_COPPER HEROKU_POSTGRESQL_AMBER -r staging --confirm your-heroku-app-name
Note:
HEROKU_POSTGRESQL_COPPER
is my old database. If you not sure what database color you old database is, refer step 7 again.
- Destroy old database:
$ heroku addons:destroy heroku-postgresql:hobby-basic -r staging
- Check your data:
$ heroku run console -r staging
> Cat.count
=> 1694
-
Go to your Heroku app > Settings > Reveal Config Vars and make sure your old database color
ENV
variable is not there. For me, I can't seeHEROKU_POSTGRESQL_COPPER_URL
anymore and that's what I'm expecting. OnlyHEROKU_POSTGRESQL_AMBER_URL
is there. -
Turn off the Maintenace Mode:
$ heroku maintenance:off -r staging
- Run
heroku login
command again to switch your Heroku CLI username. Otherwise, any deployment or changes you made after this will be tied to previous user (the user that do DB upgrade in steps above).
Done.