Ensure lex ordering of inferred migration names with respect to pgroll
migrations
#899
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.
Ensure that inferred migrations are named appropriately with respect to user created migrations to ensure correct lexicographical ordering of migration files on disk.
Reproduction
Before this PR, the problem with inferred migration naming was reproducible as follows:
Create the following migration as
01_first_migration.yaml
:Apply the migration with
pgroll start --complete
.On the target database, run some DDL:
Create another migration,
02_second_migration.yaml
:Apply the migration with
pgroll start --complete
.Now pull the migration history into a temporary directory:
$ pgroll pull tmp/
The migration history is not in the correct lexicographical order; the inferred migration is ordered after the user-created migrations:
New behaviour
This PR fixes the problem by naming inferred migrations so that they appear in the correct lexicographical order when pulled to disk with
pgroll pull
:The same steps as in the reproduction now result in these files on disk:
The inferred migration is now lex-ordered correctly between the two user migrations by appending a fixed width timestamp suffix to the previous migration name.
The inferred migration has its
version_schema
field set:cat 01_first_migration_20250613120930931268.yaml
:This is to ensure that the version schema for the inferred migration does not risk exceeding the Postgres 63 character limit for schema names.
Fixes #882