Add pgroll latest url
command
#927
Merged
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.
Add a
pgroll latest url
command to the CLI. The command returns a Postgres connection string with thesearch_path
option set to the latest version schema name. This can be used to set the connection string for an application to work with the latest schema version.By default, with no arguments,
pgroll latest url
will use the connection string set via the global--postgres-url
(orPGROLL_PG_URL
env var). If an argument is given topgroll latest url
, the command will use that as the base connection string instead.The resulting connection string sets the
search_path
by setting theoptions
parameter in the URL query string:As described in the Postgres libpq documentation.
Examples
With no connection string argument, use the connection string used by
pgroll
itself:Take the connection string as a command line argument:
$ pgroll latest url postgres://me:mypass@example.com:5432 postgres://me:mypass@example.com:5432?options=-c%20search_path%3Dpublic_05_some_migration
Like
pgroll latest migration
andpgroll latest schema
,pgroll latest url
takes a--local/-l
flag to take the latest version schema name from a directory of migration files rather than the target database. This allows for a connection string to be constructed offline, without having to lookup the latest version schema name in the target database.$ pgroll latest url --local migrations/ postgres://me:mypass@localhost:5432 postgres://me:mypass@localhost:5432?options=-c%20search_path%3Dpublic_05_some_migration
The resulting connection string can be used directly as an argument to tools like
psql
that accept a connection string on the command line:psql $(pgroll . latest url)
Documentation for the new command is added in #928
Closes #900