Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow PG* env vars as an alternative to DATABASE_URL #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brandur
Copy link
Collaborator

@brandur brandur commented Dec 24, 2024

Accept the standard set of PG* env vars as an alternative to database
configuration (e.g. PGHOST, PGDATABASE, etc.). This is mostly driven
by having done something similar for the CLI in [1], but was also
requested in #249. This turns out to be quite easy to do because pgx
does all the heavy lifting.

As noted in [1], a bonus of this is that it adds some additional
configuration options that aren't very easily doable right now, for
example around the use of an SSL certificate to connect to Postgres. We
get automatic support for these vars:

  • PGSSLCERT
  • PGSSLKEY
  • PGSSLROOTCERT
  • PGSSLPASSWORD

As part of this I also ended up rearranging some things in main.go.
Not strongly married to this design, but the idea is to get it into a
place where we can write tests for it, which previously wasn't possible.

Fixes #249.

[1] riverqueue/river#702

@@ -1,9 +1,6 @@
name: CI

env:
# A suitable URL for the test database.
DATABASE_URL: postgres://postgres:[email protected]:5432/river_dev?sslmode=disable
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't needed anywhere so I took it out so that the env is cleaner for tests where we want to work with it (i.e. we don't have to unset DATABASE_URL before testing something).

Accept the standard set of `PG*` env vars as an alternative to database
configuration (e.g. `PGHOST`, `PGDATABASE`, etc.). This is mostly driven
by having done something similar for the CLI in [1], but was also
requested in #249. This turns out to be quite easy to do because pgx
does all the heavy lifting.

As noted in [1], a bonus of this is that it adds some additional
configuration options that aren't very easily doable right now, for
example around the use of an SSL certificate to connect to Postgres. We
get automatic support for these vars:

* `PGSSLCERT`
* `PGSSLKEY`
* `PGSSLROOTCERT`
* `PGSSLPASSWORD`

As part of this I also ended up rearranging some things in `main.go`.
Not strongly married to this design, but the idea is to get it into a
place where we can write tests for it, which previously wasn't possible.

Fixes #249.

[1] riverqueue/river#702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

accept PG* env vars and making "DATABASE_URL" optional
1 participant