Skip to content
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

cleanup: provider disabled versioning states #769

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func (p *Provider) GetVersions(ctx context.Context) (current, target int64, err
// which migrations were applied. For example, if migrations were applied out of order (1,4,2,3),
// this method returns 4. If no migrations have been applied, it returns 0.
func (p *Provider) GetDBVersion(ctx context.Context) (int64, error) {
if p.cfg.disableVersioning {
return -1, errors.New("getting database version not supported when versioning is disabled")
}
return p.getDBMaxVersion(ctx, nil)
}

Expand Down Expand Up @@ -596,13 +599,17 @@ func (p *Provider) status(ctx context.Context) (_ []*MigrationStatus, retErr err
},
State: StatePending,
}
dbResult, err := p.store.GetMigration(ctx, conn, m.Version)
if err != nil && !errors.Is(err, database.ErrVersionNotFound) {
return nil, err
}
if dbResult != nil {
migrationStatus.State = StateApplied
migrationStatus.AppliedAt = dbResult.Timestamp
// If versioning is disabled, we can't check the database for applied migrations, so we
// assume all migrations are pending.
if !p.cfg.disableVersioning {
dbResult, err := p.store.GetMigration(ctx, conn, m.Version)
if err != nil && !errors.Is(err, database.ErrVersionNotFound) {
return nil, err
}
if dbResult != nil {
migrationStatus.State = StateApplied
migrationStatus.AppliedAt = dbResult.Timestamp
}
}
status = append(status, migrationStatus)
}
Expand Down
14 changes: 6 additions & 8 deletions provider_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,9 @@ func TestNoVersioning(t *testing.T) {
upResult, err := p.Up(ctx)
check.NoError(t, err)
check.Number(t, len(upResult), 2)
// Confirm no changes to the versioned schema in the DB
currentVersion, err := p.GetDBVersion(ctx)
check.NoError(t, err)
check.Number(t, baseVersion, currentVersion)
// When versioning is disabled, we cannot track the version of the seed files.
_, err = p.GetDBVersion(ctx)
check.HasError(t, err)
seedOwnerCount, err := countSeedOwners(db)
check.NoError(t, err)
check.Number(t, seedOwnerCount, wantSeedOwnerCount)
Expand All @@ -519,10 +518,9 @@ func TestNoVersioning(t *testing.T) {
downResult, err := p.DownTo(ctx, 0)
check.NoError(t, err)
check.Number(t, len(downResult), 2)
// Confirm no changes to the versioned schema in the DB
currentVersion, err := p.GetDBVersion(ctx)
check.NoError(t, err)
check.Number(t, baseVersion, currentVersion)
// When versioning is disabled, we cannot track the version of the seed files.
_, err = p.GetDBVersion(ctx)
check.HasError(t, err)
seedOwnerCount, err := countSeedOwners(db)
check.NoError(t, err)
check.Number(t, seedOwnerCount, 0)
Expand Down