graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.
MIT License
751 stars 58 forks source link

gmrc `connectionString` should be ignored if `DATABASE_URL` exists in the env #84

Closed samlevin closed 4 years ago

samlevin commented 4 years ago

Hey Benjie. We've nearly completed our adoption of graphile-migrate and as a team, we're loving it. A lot of great philosophies at play. Awesome work all around.

Our development team has a 'zero config' dev environment philosophy where a lot of settings are hard-coded to repositories (with insecure defaults). We're trying to replicate this for graphile-migrate but the migrate command appears to be preferring connectionString - even though DATABASE_URL exists.

Thoughts? ENV var precedence is fairly typical in the config world. Am I right in assuming that migrate would/should follow suit?

benjie commented 4 years ago

No; explicit always wins over implicit. If you provide a connection string explicitly via the Graphile Migrate config file then that will override the implicit and generic environmental variable DATABASE_URL that may have come from anywhere and could relate to some other service such as PostGraphile or Graphile Worker or even a completely different project.

Perhaps there's an alternative way we can solve this; for example a .js config file where you can set connectionString: process.env.DATABASE_URL || "fallback"

This'd be the place to apply that change:

https://github.com/graphile/migrate/blob/08e0b271aeefa5fcabf8c7a6d8a9380b307a571c/src/commands/_common.ts#L7-L23

I think read .gmrc if present, otherwise try .gmrc.js.