-
Notifications
You must be signed in to change notification settings - Fork 106
Update pgroll latest
to take account of migration version_schema
#896
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
Conversation
20e299c
to
88edd61
Compare
88edd61
to
ad4a21e
Compare
Add new functions to `pkg/roll` concerning retrieving latest migrations locally and remotely: * `LatestMigrationNameLocal`: Returns the name of the latest migration in a local migrations directory * `LatestMigrationNameRemote`: Returns the name of the latest migration in the target database. Add tests for both of these new functions. Together with the existing `LatestVersionLocal` and `LatestVersionRemote` functions, these new functions make it possible to retrieve latest migration information, taking into account both the version schema and the migration name.
Previous behaviour: * `pgroll latest schema`: would return the most recent migration name prefixed with the schema name, eg `public_01_create_table`. * `pgroll latest migration`: would return the most receent migration name without the schema prefix, eg `01_create_table`. New behaviour: * `pgroll latest schema`: returns the version schema name of the most recent migration prefixed with the schema name, eg `public_01_set_by_version_schema_field` * `pgroll latest migration`: returns the name of the most recent migration, without the schema prefix, eg, `01_create_table`.
* Tidy up the `latest` command documentation to clarify the difference between the schema version and migration name outputs. * Add a section to the operations documentation explaining the difference between migration names and version schema names.
ad4a21e
to
a833fb2
Compare
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, as I understand it, this is an internal change and not breaking in the public API correct?
Yes, the command names and flags are unchanged. |
#884 added support for the
version_schema
field in migration files, allowing a migration to specify the name of the version schema that will be created when the migration is applied:When applied as
pgroll start 01_create_table.yaml
, this migration will take the name of its version schema from the migration file:If
version_schema
is not specified, the name of the version schema defaults to the filename, as before.This PR updates the
pgroll latest
command to take account of this new behaviour, where the version schema name can be decoupled from its filename.Previous behaviour:
pgroll latest schema
: would return the most recent migration name prefixed with the schema name, egpublic_01_create_table
.pgroll latest migration
: would return the most receent migration name without the schema prefix, eg01_create_table
.New behaviour:
pgroll latest schema
: returns the version schema name of the most recent migration prefixed with the schema name, egpublic_01_set_by_version_schema_field
pgroll latest migration
: returns the name of the most recent migration, without the schema prefix, eg,01_create_table
.Examples
Run:
to apply all example migrations. Now:
# get the **name** of the latest migration applied to the target database $ pgroll latest migration 56_with_version_schema
# get the **version schema name** of the latest migration applied to the target database $ pgroll latest schema public_with_version_schema
# get the **name** of the latest migration in the migrations/ folder $ pgroll latest migration --local examples/ 56_with_version_schema
# get the **version schema name** of the latest migration in the migrations/ folder $ pgroll latest schema --local examples/ public_with_version_schema