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: cleanup change history store (#5454)
Danny Xu6a78df8bb46e
diff --git a/backend/store/instance_change_history.go b/backend/store/instance_change_history.goindex 571719f031..285ad89b17 100644--- a/backend/store/instance_change_history.go+++ b/backend/store/instance_change_history.go@@ -36,7 +36,7 @@ type InstanceChangeHistoryMessage struct {Payload string// Output only- ID int64+ ID stringDeleted bool}@@ -52,7 +52,7 @@ type FindInstanceChangeHistoryMessage struct {// UpdateInstanceChangeHistoryMessage is for updating an instance change history.type UpdateInstanceChangeHistoryMessage struct {- ID int64+ ID stringStatus *db.MigrationStatusExecutionDurationNs *int64@@ -169,7 +169,8 @@ func (*Store) createInstanceChangeHistoryImpl(ctx context.Context, tx *Tx, creati := 0for rows.Next() {- var id, createdTs int64+ var id string+ var createdTs int64if err := rows.Scan(&id, &createdTs); err != nil {return nil, err}@@ -219,7 +220,7 @@ func convertInstanceChangeHistoryToMigrationHistory(change *InstanceChangeHistor}return &db.MigrationHistory{- ID: strconv.FormatInt(change.ID, 10),+ ID: change.ID,Creator: "",CreatedTs: change.CreatedTs,Updater: "",@@ -412,37 +413,6 @@ func (s *Store) ListInstanceChangeHistory(ctx context.Context, find *FindInstancreturn list, nil}-// UpdateInstanceChangeHistoryAsDone updates a change history to done.-func (s *Store) UpdateInstanceChangeHistoryAsDone(ctx context.Context, migrationDurationNs int64, updatedSchema string, insertedID string) error {- status := db.Done- id, err := strconv.ParseInt(insertedID, 10, 64)- if err != nil {- return err- }- update := &UpdateInstanceChangeHistoryMessage{- ID: id,- ExecutionDurationNs: &migrationDurationNs,- Status: &status,- Schema: &updatedSchema,- }- return s.UpdateInstanceChangeHistory(ctx, update)-}--// UpdateInstanceChangeHistoryAsFailed updates a change history to failed.-func (s *Store) UpdateInstanceChangeHistoryAsFailed(ctx context.Context, migrationDurationNs int64, insertedID string) error {- status := db.Failed- id, err := strconv.ParseInt(insertedID, 10, 64)- if err != nil {- return err- }- update := &UpdateInstanceChangeHistoryMessage{- ID: id,- ExecutionDurationNs: &migrationDurationNs,- Status: &status,- }- return s.UpdateInstanceChangeHistory(ctx, update)-}-// UpdateInstanceChangeHistory updates an instance change history.// it deprecates the old UpdateHistoryAsDone and UpdateHistoryAsFailed.func (s *Store) UpdateInstanceChangeHistory(ctx context.Context, update *UpdateInstanceChangeHistoryMessage) error {@@ -553,7 +523,7 @@ func (s *Store) GetLargestInstanceChangeHistoryVersionSinceBaseline(ctx context.where, args = append(where, fmt.Sprintf("sequence >= $%d", len(args)+1)), append(args, sequence)query := `- SELECT+ SELECTMAX(version)FROM instance_change_historyWHERE ` + strings.Join(where, " AND ")@@ -609,7 +579,7 @@ func (s *Store) CreatePendingInstanceChangeHistory(ctx context.Context, sequencereturn "", err}- return fmt.Sprintf("%d", list[0].ID), nil+ return list[0].ID, nil}// ListInstanceHavingInstanceChangeHistory finds the instance id lists that have instance change history.diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex fc719f4c75..e88c72583f 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -611,18 +611,23 @@ func BeginMigration(ctx context.Context, store *store.Store, m *db.MigrationInfo}// EndMigration updates the migration history record to DONE or FAILED depending on migration is done or not.-func EndMigration(ctx context.Context, store *store.Store, startedNs int64, insertedID string, updatedSchema string, isDone bool) error {- var err error+func EndMigration(ctx context.Context, storeInstance *store.Store, startedNs int64, insertedID string, updatedSchema string, isDone bool) error {migrationDurationNs := time.Now().UnixNano() - startedNs-+ update := &store.UpdateInstanceChangeHistoryMessage{+ ID: insertedID,+ ExecutionDurationNs: &migrationDurationNs,+ }if isDone {- err = store.UpdateInstanceChangeHistoryAsDone(ctx, migrationDurationNs, updatedSchema, insertedID)// Upon success, update the migration history as 'DONE', execution_duration_ns, updated schema.+ status := db.Done+ update.Status = &status+ update.Schema = &updatedSchema} else {// Otherwise, update the migration history as 'FAILED', execution_duration.- err = store.UpdateInstanceChangeHistoryAsFailed(ctx, migrationDurationNs, insertedID)+ status := db.Failed+ update.Status = &status}- return err+ return storeInstance.UpdateInstanceChangeHistory(ctx, update)}// FindNextPendingStep finds the next pending step in the approval flow.