Procfile: automatically run migrations on Heroku deploy
Final result: automatically run migrations right when app is deployed! #
The Problem #
When you deploy to production, afterwards you most likely write a console command like heroku run rails db:migrate
, right?
Well, there’s the Procfile
- a file where you list commands that should be run on deploy. Heroku automatically scans for it.
For other platforms (not heroku) you might need a tool like foreman.
How to use: #
-
Create a file named
Procfile
in your application root folder -
Inside
Procfile
add these lines to run migrations right when the app gets deployed:web: bundle exec rails s release: rails db:migrate
Bonus: also start sidekiq on deploy #
Procfile
web: bundle exec rails s
worker: bundle exec sidekiq -c 2
release: rails db:migrate
Did you like this article? Did it save you some time?