The Heroku Pipeline (aka ‘Pipelines’)

Pipelines are a modern way to work on Heroku. From the Heorku docs:

pipeline is a group of Heroku apps that share the same codebase. Each app in a pipeline represents one of the following stages in a continuous delivery workflow: Development, Review, Staging, Production

Heroku Docs

Using a pipeline allows for a streamlined continuous delivery workflow— or producing software in short, iterative cycles and constantly delivering to production. This benchmark is typically seen as the key to successful software develompent.

Setting up your pipeline is beyond the scope of this article, but if you have a Ruby or Node deployment please reach out to my company Helios Dev Shop and we can gladly help you get your pipeline set up.

The 30-Second Timeout and Other Limitations

Prebooting

The Rails Console

run heroku rails console -a <yourappname>

Heroku Postgres

Heroku Postgres is the Heroku-provided add on that’s the easiest way to set up your database. Some things to note about Heroku Postgres and Rails are:

Rails Database Migrations

Don’t run rails db:create on Heroku—  it won’t work. Heroku manages the database name for your and gives it a non-readable random string of characters. As well, you should NOT configure your database in your config/database.yml file, instead letting it be configured by the DATABASE_URL config var, which is automatically managed for you.

You will also have a hard time running db:drop, even if you run it with the flag DISABLE_DATABASE_ENVIRONMENT_CHECK=1

That’s because Heroku Postgres doesn’t give you direct access to create & drop databases. If you need to fully drop your database, just remove the resource from the Resources tab and then re-add it.

However, you will need to run rails db:migrate. As well, the way to migrate your database on modern deployments is to make a file at the root of your repo called release-tasks.sh. Put this into the file:

## Step to execute
bundle exec rails db:migrate

# check for a good exit
if [ $? -ne 0 ]
then
puts "*** RELEASE COMMAND FAILED"
# something went wrong; convey that and exit
exit 1
fi

This will trigger the “Release” phase after the deployment, which happens in a slightly different way depending on whether or not you are deploying directly or using the Heroku Pipeline. Either way, the release tasks file triggers the database migration post-deploy.