Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to restart Heroku after every migration?

Recently I had an issue where my db scheme change wasn't being reflected on Heroku PG. I double checked to see that both migration and seed succeeded. What was even weirder was that the db scheme change worked fine on a staging heroku deployment (after the exact same migration/seed). After some searching around, I learned that you are supposed to restart heroku after migrations via:

heroku restart --app=app_name

I've never had to do this (I'm not exactly a veteran, but I've run a good amount of migrations before and have never had to restart heroku for this particular reason).

Do I actually need to be restarting heroku after each migration? Or is this more of a case by case thing?

like image 629
Tristan Tao Avatar asked May 23 '14 19:05

Tristan Tao


People also ask

Does heroku run migrations automatically?

Heroku makes deploying Ruby web app a breeze, however it doesn't run rake db:migrate automatically each time you push a new commit to it.

What does heroku restart do?

TIP By default heroku restart will restart all of your dynos, but you can specify a specific dyno to restart (e.g. heroku ps:restart web. 1 ), or all dynos of a specific type (e.g. heroku ps:restart web ).

How do I stop heroku app from running?

If you wish to stop a running one-off dyno, use heroku ps:stop with its name. A one-off dyno will not stop if you issue heroku ps:restart on your application.


2 Answers

If you make changes to your DB via migrations then you will need to restart the application on Heroku. When Rails starts in production mode it caches the DB schema. Migrations run in one off processes which the running web process is not aware of. So for it to pick up the changes you need to restart at least your web processes. If your application was idling when you deployed and you ran the migrations it would pick up the new schema as the app started.

like image 190
John Beynon Avatar answered Oct 13 '22 12:10

John Beynon


You need to get your app to pick up the new migration. Restarting the app works just fine. Or you can clear the schema cache:

heroku run rake db:schema:cache:clear --app=app_name
like image 39
John Hinnegan Avatar answered Oct 13 '22 13:10

John Hinnegan