Skip to content

Using with Heroku

Benjie Gillam edited this page Sep 26, 2019 · 7 revisions

DEPRECATED! Please see https://graphile.org/postgraphile/deploying-heroku/ instead


It's possible to use Postgraphile on Heroku with either AWS RDS or Heroku Postgres.

AWS RDS

We recommend using RDS as the database since RDS allows you to easily create roles. You should force_ssl in this case, and to ensure Postgraphile connects to RDS using SSL you need to add ?ssl=1 to the connection string, e.g. heroku config:set DATABASE_URL="postgres://...rdshost.../db_name?ssl=1"

Heroku Postgres

It is also possible to use Postgraphile with Heroku Postgres too with a bit more setup (and money!).

  1. Create a database if not already. The database must be of the Standard-0 tier ($50/month) or higher, otherwise you will not be able to create additional credentials.
  2. Create credentials on https://data.heroku.com for each Postgres role that you wish to use. For example, create a credential for postgraphile (which your app will use to log in with), schema_person and schema_anonymous.
  3. Attach the postgraphile credential to your app, so that there should now be two credentials attached to your app (default and postgraphile).
  4. Use the POSTGRAPHILE environment variable instead of DATABASE_URL in your app's code to connect to Postgres with this credential.
  5. Don't forget to use SSL too (e.g. with the env var PGSSLMODE=require)!

Heroku CI with Heroku Postgres

If you'd also like to use Postgraphile with Heroku Postgres on Heroku CI, this is possible too. Heroku provides in-dyno databases during CI runs, which have no restrictions on using CREATE ROLE unlike normal Heroku Postgres databases. It's therefore possible to run a script that creates the required roles at the beginning of each test run, and connect as usual.

Step by Step Instructions to deploy on Heroku

  1. Create a project directory mkdir project_folder_name
  2. Go into that directory and initialise git: cd project_folder_name && git init
  3. Add postgraphile: yarn add postgraphile
  4. Commit everything: git add . && git commit -m "Initial commit"
  5. Add the heroku remote heroku git:remote -a heroku_app_name
  6. Configure Heroku to use the right url heroku config:set RDS_URL="postgres://user:pass@rdshost/dbname?ssl=1" -a heroku_app_name
  7. Create Procfile: echo 'web: postgraphile -c $RDS_URL --host 0.0.0.0 --port $PORT' >> Procfile
  8. Deploy: git push heroku master