-
-
Notifications
You must be signed in to change notification settings - Fork 571
Using with Heroku
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.
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"
It is also possible to use Postgraphile with Heroku Postgres too with a bit more setup (and money!).
- 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.
- 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
andschema_anonymous
. - Attach the
postgraphile
credential to your app, so that there should now be two credentials attached to your app (default
andpostgraphile
). - Use the
POSTGRAPHILE
environment variable instead ofDATABASE_URL
in your app's code to connect to Postgres with this credential. - Don't forget to use SSL too (e.g. with the env var
PGSSLMODE=require
)!
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.
- Create a project directory
mkdir project_folder_name
- Go into that directory and initialise git:
cd project_folder_name && git init
- Add postgraphile:
yarn add postgraphile
- Commit everything:
git add . && git commit -m "Initial commit"
- Add the heroku remote
heroku git:remote -a heroku_app_name
- Configure Heroku to use the right url
heroku config:set RDS_URL="postgres://user:pass@rdshost/dbname?ssl=1" -a heroku_app_name
- Create Procfile:
echo 'web: postgraphile -c $RDS_URL --host 0.0.0.0 --port $PORT' >> Procfile
- Deploy:
git push heroku master