Heroku database URL sync¶
Table of contents
Introduction¶
Hasura Cloud can keep your project’s Heroku database URL i.e. the PG_DATABASE_URL
env var in sync with Postgres from a Heroku app.
This is especially helpful in cases when the database credentials of Heroku Postgres are rotated automatically by Heroku.
Note
The database sync automatically gets disconnected if you transfer the ownership of your project to another account. The new project owner can restart the sync with the Heroku account that they have connected their Hasura Cloud account to.
Enable Heroku database URL sync¶
If you create a project with a Heroku trial database using the Hasura console, your project has the Heroku database URL sync enabled by default, which means, Hasura Cloud keeps the database URL of your project in sync with the related Heroku Postgres.
Opt out¶
If your project has Heroku database URL sync enabled, you can opt out as follows:
How it works?¶
Heroku database URL sync is useful because Postgres credentials of Heroku Postgres are sometimes rotated thus making the old database URL invalid. Hasura Cloud listens to the changes in the database URL of your app and keeps the project updated. This is done using:
- Heroku Releases: Whenever a config variable of a Heroku app changes, a new
release
is made for that app. - Heroku Webhooks: Heroku allows us to get notifications about these releases on a webhook.
Whenever Postgres credentials of a Heroku app are rotated:
- The
DATABASE_URL
config variable of the Heroku app gets updated with the new credentials. - The config variable change triggers a new release, which notifies Hasura Cloud’s webhook.
- When Hasura Cloud is notified about the new release, it fetches the newest database URL from Heroku and updates the
PG_DATABASE_URL
env var of your project with it. - This way, your project is always configured with the correct database URL.