Skip to content

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Jun 17, 2025

Fix the problem described in #915 where pgroll latest schema will return version schema names for which no version schema exists in the database, such as for inferred migrations.


  1. Apply a migration
pgroll  start examples/01_create_tables.yaml --complete
  1. Create an inferred migration
CREATE TABLE foo(id int PRIMARY KEY)
  1. Run pgroll latest schema

Before this PR the output would be incorrect:

public_sql_fca0901e

The most recent migration (inferred from the CREATE TABLE) did not create a version schema - the most recent schema version is still public_01_create_tables.

This PR corrects the behaviour of pgroll latest schema to consider only migrations for which a version schema exists. So the output is:

public_01_create_tables

as expected.


Fixes #915

Related to #872

@github-actions github-actions bot temporarily deployed to Docs Preview June 17, 2025 12:00 Inactive
@andrew-farries andrew-farries marked this pull request as ready for review June 17, 2025 12:08
@andrew-farries andrew-farries requested a review from kvch June 17, 2025 12:08
@andrew-farries
Copy link
Collaborator Author

Coverage is failing because this is stacked on #914.

When rebased it should show increased coverage of the pkg/state package.

@andrew-farries andrew-farries force-pushed the fix-pgroll-latest-schema-with-inferred-migs branch from 365c1f3 to fc522e4 Compare June 17, 2025 12:19
@github-actions github-actions bot temporarily deployed to Docs Preview June 17, 2025 12:19 Inactive
@andrew-farries andrew-farries requested a review from divyenduz June 17, 2025 12:24
Base automatically changed from remove-param-from-previous-migration-function to main June 17, 2025 15:05
Add a new `find_version_schema` function to `init.sql` that retrieves
version schema names schema based on a specified depth.

Define the `previous_version` and `latest_version` in terms of this new
function.
Remove redundant `includeInferred` parameter from
`State.PreviousVersion` method calls.
Ensure that an inferred migration name without a version schema is not
returned when calling `LatestVersionRemote`.
Move the latest and previous version and migration functions into their
own file in the `pkg/state` package.
Ensure that the:
* `LatestMigration` and `PreviousMigration` methods
* `LatestVersion` and `PreviousVersion` methods

work correctly in various scenarios.
@andrew-farries andrew-farries force-pushed the fix-pgroll-latest-schema-with-inferred-migs branch from fc522e4 to c51b6a9 Compare June 17, 2025 15:06
@github-actions github-actions bot temporarily deployed to Docs Preview June 17, 2025 15:06 Inactive
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgroll/pkg/roll 79.87% (ø)
github.com/xataio/pgroll/pkg/state 66.67% (+5.04%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgroll/pkg/roll/execute.go 79.64% (ø) 167 133 34
github.com/xataio/pgroll/pkg/state/latest.go 80.00% (+80.00%) 20 (+20) 16 (+16) 4 (+4) 🌟
github.com/xataio/pgroll/pkg/state/state.go 57.76% (+4.73%) 161 (-20) 93 (-3) 68 (-17) 👍

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

  • github.com/xataio/pgroll/pkg/roll/latest_test.go
  • github.com/xataio/pgroll/pkg/state/latest_test.go

@andrew-farries andrew-farries merged commit 589bc33 into main Jun 18, 2025
30 checks passed
@andrew-farries andrew-farries deleted the fix-pgroll-latest-schema-with-inferred-migs branch June 18, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pgroll latest schema incorrectly returns versions for which no version schema exists
3 participants