Skip to content

Commit

Permalink
Rename CheckPending to GetVersions (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman authored May 3, 2024
1 parent 8c8def4 commit 992628d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Add `CheckPending` method to `goose.Provider` to check if there are pending migrations, returns
the current (max db) version and the latest (max file) version. (#756)
- Add `GetVersions` method to `goose.Provider`, returns the current (max db) version and the latest
(max filesystem) version. (#756)
- Clarify `GetLatestVersion` method MUST return `ErrVersionNotFound` if no latest migration is
found. Previously it was returning a -1 and nil error, which was inconsistent with the rest of the
API surface.
Expand Down
10 changes: 5 additions & 5 deletions internal/testing/integration/postgres_locking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func TestPostgresPending(t *testing.T) {
hasPending, err := p.HasPending(context.Background())
check.NoError(t, err)
boolCh <- hasPending
current, target, err := p.CheckPending(context.Background())
current, target, err := p.GetVersions(context.Background())
check.NoError(t, err)
check.Number(t, current, int64(wantCurrent))
check.Number(t, target, int64(wantTarget))
Expand Down Expand Up @@ -492,7 +492,7 @@ SELECT pg_sleep_for('4 seconds');
return err
}
check.Bool(t, hasPending, true)
current, target, err := newProvider.CheckPending(context.Background())
current, target, err := newProvider.GetVersions(context.Background())
if err != nil {
return err
}
Expand All @@ -506,7 +506,7 @@ SELECT pg_sleep_for('4 seconds');
return err
}
check.Bool(t, hasPending, false)
current, target, err := oldProvider.CheckPending(context.Background())
current, target, err := oldProvider.GetVersions(context.Background())
if err != nil {
return err
}
Expand All @@ -531,7 +531,7 @@ SELECT pg_sleep_for('4 seconds');
hasPending, err := oldProvider.HasPending(context.Background())
check.NoError(t, err)
check.Bool(t, hasPending, false)
current, target, err := oldProvider.CheckPending(context.Background())
current, target, err := oldProvider.GetVersions(context.Background())
check.NoError(t, err)
check.Number(t, current, lastVersion)
check.Number(t, target, lastVersion)
Expand All @@ -541,7 +541,7 @@ SELECT pg_sleep_for('4 seconds');
hasPending, err = newProvider.HasPending(context.Background())
check.NoError(t, err)
check.Bool(t, hasPending, false)
current, target, err = newProvider.CheckPending(context.Background())
current, target, err = newProvider.GetVersions(context.Background())
check.NoError(t, err)
check.Number(t, current, lastVersion+1)
check.Number(t, target, lastVersion+1)
Expand Down
15 changes: 5 additions & 10 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,12 @@ func (p *Provider) HasPending(ctx context.Context) (bool, error) {
return p.hasPending(ctx)
}

// CheckPending returns the current database version and the target version to migrate to. If there
// are no pending migrations, the target version will be the same as the current version.
// GetVersions returns the max database version and the target version to migrate to.
//
// Note, this method will not use a SessionLocker if one is configured. This allows callers to check
// for pending migrations without blocking or being blocked by other operations.
//
// If out-of-order migrations are enabled this method is not suitable for checking pending
// migrations because it ONLY returns the highest version in the database. Instead, use the
// [HasPending] method.
func (p *Provider) CheckPending(ctx context.Context) (current, target int64, err error) {
return p.checkPending(ctx)
// for versions without blocking or being blocked by other operations.
func (p *Provider) GetVersions(ctx context.Context) (current, target int64, err error) {
return p.getVersions(ctx)
}

// GetDBVersion returns the highest version recorded in the database, regardless of the order in
Expand Down Expand Up @@ -491,7 +486,7 @@ func (p *Provider) apply(
return p.runMigrations(ctx, conn, []*Migration{m}, d, true)
}

func (p *Provider) checkPending(ctx context.Context) (current, target int64, retErr error) {
func (p *Provider) getVersions(ctx context.Context) (current, target int64, retErr error) {
conn, cleanup, err := p.initialize(ctx, false)
if err != nil {
return -1, -1, fmt.Errorf("failed to initialize: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions provider_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ func TestPending(t *testing.T) {
check.NoError(t, err)
// Even though the latest migration HAS been applied, there are still pending out-of-order
// migrations.
current, target, err := p.CheckPending(ctx)
current, target, err := p.GetVersions(ctx)
check.NoError(t, err)
check.Number(t, current, 3)
check.Number(t, target, len(fsys))
Expand All @@ -804,7 +804,7 @@ func TestPending(t *testing.T) {
hasPending, err = p.HasPending(ctx)
check.NoError(t, err)
check.Bool(t, hasPending, false)
current, target, err = p.CheckPending(ctx)
current, target, err = p.GetVersions(ctx)
check.NoError(t, err)
check.Number(t, current, target)
})
Expand All @@ -824,7 +824,7 @@ func TestPending(t *testing.T) {
check.NoError(t, err)
// TODO(mf): revisit the pending check behavior in addition to the HasPending
// method.
current, target, err := p.CheckPending(ctx)
current, target, err := p.GetVersions(ctx)
check.NoError(t, err)
check.Number(t, current, versionToApply)
check.Number(t, target, len(fsys))
Expand Down

0 comments on commit 992628d

Please sign in to comment.