Respect libpq env vars in the default Postgres URL - #1046
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
When --postgres-url is not set, pgroll fell back to a hardcoded postgres://postgres:postgres@localhost default and ignored the standard libpq environment variables. That is surprising for anyone used to psql and friends, which pick up PGHOST, PGUSER and so on. Keep defaulting to a local Postgres when nothing is set, but let PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE and PGSSLMODE override the individual fields when they are present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #717.
Right now if you run pgroll without
--postgres-urlit falls back to a hardcodedpostgres://postgres:postgres@localhostand silently ignores the libpq environment variables, so people coming from psql get a confusing connection attempt instead of one that uses theirPGHOST/PGUSER/etc.Following the direction in the issue, this keeps the local Postgres default when nothing is set, but lets
PGHOST,PGPORT,PGUSER,PGPASSWORD,PGDATABASEandPGSSLMODEoverride the individual fields when they are present. With no env vars set the default string is unchanged, so existing setups keep working.The default is now built in
internal/connstr.DefaultURL()and used as the flag default incmd/root.go. Added table tests for the env var handling and a note in the CLI docs.