cleanup: provider disabled versioning states (#769)

pull/771/head
Michael Fridman 2024-05-11 14:51:15 -04:00 committed by GitHub
parent 992628d83a
commit 9309665e0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 15 deletions

View File

@ -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), // 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. // this method returns 4. If no migrations have been applied, it returns 0.
func (p *Provider) GetDBVersion(ctx context.Context) (int64, error) { 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) return p.getDBMaxVersion(ctx, nil)
} }
@ -596,13 +599,17 @@ func (p *Provider) status(ctx context.Context) (_ []*MigrationStatus, retErr err
}, },
State: StatePending, State: StatePending,
} }
dbResult, err := p.store.GetMigration(ctx, conn, m.Version) // If versioning is disabled, we can't check the database for applied migrations, so we
if err != nil && !errors.Is(err, database.ErrVersionNotFound) { // assume all migrations are pending.
return nil, err if !p.cfg.disableVersioning {
} dbResult, err := p.store.GetMigration(ctx, conn, m.Version)
if dbResult != nil { if err != nil && !errors.Is(err, database.ErrVersionNotFound) {
migrationStatus.State = StateApplied return nil, err
migrationStatus.AppliedAt = dbResult.Timestamp }
if dbResult != nil {
migrationStatus.State = StateApplied
migrationStatus.AppliedAt = dbResult.Timestamp
}
} }
status = append(status, migrationStatus) status = append(status, migrationStatus)
} }

View File

@ -506,10 +506,9 @@ func TestNoVersioning(t *testing.T) {
upResult, err := p.Up(ctx) upResult, err := p.Up(ctx)
check.NoError(t, err) check.NoError(t, err)
check.Number(t, len(upResult), 2) check.Number(t, len(upResult), 2)
// Confirm no changes to the versioned schema in the DB // When versioning is disabled, we cannot track the version of the seed files.
currentVersion, err := p.GetDBVersion(ctx) _, err = p.GetDBVersion(ctx)
check.NoError(t, err) check.HasError(t, err)
check.Number(t, baseVersion, currentVersion)
seedOwnerCount, err := countSeedOwners(db) seedOwnerCount, err := countSeedOwners(db)
check.NoError(t, err) check.NoError(t, err)
check.Number(t, seedOwnerCount, wantSeedOwnerCount) check.Number(t, seedOwnerCount, wantSeedOwnerCount)
@ -519,10 +518,9 @@ func TestNoVersioning(t *testing.T) {
downResult, err := p.DownTo(ctx, 0) downResult, err := p.DownTo(ctx, 0)
check.NoError(t, err) check.NoError(t, err)
check.Number(t, len(downResult), 2) check.Number(t, len(downResult), 2)
// Confirm no changes to the versioned schema in the DB // When versioning is disabled, we cannot track the version of the seed files.
currentVersion, err := p.GetDBVersion(ctx) _, err = p.GetDBVersion(ctx)
check.NoError(t, err) check.HasError(t, err)
check.Number(t, baseVersion, currentVersion)
seedOwnerCount, err := countSeedOwners(db) seedOwnerCount, err := countSeedOwners(db)
check.NoError(t, err) check.NoError(t, err)
check.Number(t, seedOwnerCount, 0) check.Number(t, seedOwnerCount, 0)