Connecting Rails to a PostgreSQL DB on Heroku
This week we had to do a quick deployment of a backend for one of our clients and we decided to use Heroku. During the deployment, we noticed the official documentation was missing two key configurations which are highlighted below.
Introduction
We had to deploy a simple Rails backend to Heroku for one of our clients. Given we had a very small number of hours available for the deployment, we opted for Heroku instead of the usual AWS Elastic Beanstalk or equivalents. That way we could have a deploy running in 1 to 2 hours of work instead of the usual 6 to 8.
However, upon configuring the deployment we noticed that the oficial Heroku documentation does not include two important configurations required to run a real application.
1 — Run Migrations
Whenever a new version of the application is deployed we should run the corresponding migrations. Rails does not complain in production about missing migrations but your code sure will!
To that end, edit your Procfile
(spelled exactly like that with capital P on the root of your repo):
release: rails db:migrate
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}