Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: always update prev schema (#9599)
p0nyc4e27a228599
diff --git a/backend/store/instance_change_history.go b/backend/store/instance_change_history.goindex 4ccbd1d56d..d79a1477f2 100644--- a/backend/store/instance_change_history.go+++ b/backend/store/instance_change_history.go@@ -79,6 +79,7 @@ type UpdateInstanceChangeHistoryMessage struct {Status *db.MigrationStatusExecutionDurationNs *int64Schema *string+ SchemaPrev *stringSheet *int}@@ -664,6 +665,9 @@ func (s *Store) UpdateInstanceChangeHistory(ctx context.Context, update *UpdateIif v := update.Schema; v != nil {set, args = append(set, fmt.Sprintf("schema = $%d", len(args)+1)), append(args, *v)}+ if v := update.SchemaPrev; v != nil {+ set, args = append(set, fmt.Sprintf("schema_prev = $%d", len(args)+1)), append(args, *v)+ }if v := update.Sheet; v != nil {set, args = append(set, fmt.Sprintf("sheet_id = $%d", len(args)+1)), append(args, *v)}diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex 401d214131..04bfb73520 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -258,7 +258,7 @@ func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, sstartedNs := time.Now().UnixNano()defer func() {- if err := EndMigration(ctx, s, startedNs, insertedID, updatedSchema, sheetID, resErr == nil /* isDone */); err != nil {+ if err := EndMigration(ctx, s, startedNs, insertedID, updatedSchema, prevSchemaBuf.String(), sheetID, resErr == nil /* isDone */); err != nil {slog.Error("Failed to update migration history record",log.BBError(err),slog.String("migration_id", migrationHistoryID),@@ -365,13 +365,15 @@ func BeginMigration(ctx context.Context, stores *store.Store, m *db.MigrationInf}// EndMigration updates the migration history record to DONE or FAILED depending on migration is done or not.-func EndMigration(ctx context.Context, storeInstance *store.Store, startedNs int64, insertedID string, updatedSchema string, sheetID *int, isDone bool) error {+func EndMigration(ctx context.Context, storeInstance *store.Store, startedNs int64, insertedID string, updatedSchema, schemaPrev string, sheetID *int, isDone bool) error {migrationDurationNs := time.Now().UnixNano() - startedNsupdate := &store.UpdateInstanceChangeHistoryMessage{ID: insertedID,ExecutionDurationNs: &migrationDurationNs,// Update the sheet ID just in case it has been updated.Sheet: sheetID,+ // Update schemaPrev because we might be re-using a previous change history entry.+ SchemaPrev: &schemaPrev,}if isDone {// Upon success, update the migration history as 'DONE', execution_duration_ns, updated schema.