Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: remove IssueID from MigrationInfo (#8660)

p0ny82f1cfc8f193
diff --git a/backend/migrator/migrator.go b/backend/migrator/migrator.go
index 78c22c204d..1357e82f29 100644
--- a/backend/migrator/migrator.go
+++ b/backend/migrator/migrator.go
@@ -137,7 +137,7 @@ func initializeSchema(ctx context.Context, storeInstance *store.Store, metadataD
if _, err := metadataDriver.GetDB().ExecContext(ctx, stmt); err != nil {
return err
}
- if err := storeInstance.CreateInstanceChangeHistory(ctx, &store.InstanceChangeHistoryMessage{
+ if err := storeInstance.CreateInstanceChangeHistoryForMigrator(ctx, &store.InstanceChangeHistoryMessage{
CreatorID: api.SystemBotID,
InstanceUID: nil,
DatabaseUID: nil,
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.go
index 8bc4718fc6..97fb04a4e7 100644
--- a/backend/plugin/db/driver.go
+++ b/backend/plugin/db/driver.go
@@ -143,7 +143,7 @@ type MigrationInfo struct {
// InstanceID nil is metadata database.
InstanceID *int
DatabaseID *int
- IssueIDInt *int
+ IssueUID *int
CreatorID int
ReleaseVersion string
@@ -156,7 +156,6 @@ type MigrationInfo struct {
Status MigrationStatus
Description string
Creator string
- IssueID string
// Payload contains JSON-encoded string of VCS push event if the migration is triggered by a VCS push event.
Payload *storepb.InstanceChangeHistoryPayload
// Force is used to execute migration disregarding any migration history with PENDING or FAILED status.
diff --git a/backend/runner/taskrun/database_create_executor.go b/backend/runner/taskrun/database_create_executor.go
index a473427690..ac0ddcb6ee 100644
--- a/backend/runner/taskrun/database_create_executor.go
+++ b/backend/runner/taskrun/database_create_executor.go
@@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"log/slog"
- "strconv"
"strings"
"time"
@@ -287,8 +286,7 @@ func (exec *DatabaseCreateExecutor) createInitialSchema(ctx context.Context, dri
log.BBError(err),
)
} else {
- mi.IssueID = strconv.Itoa(issue.UID)
- mi.IssueIDInt = &issue.UID
+ mi.IssueUID = &issue.UID
}
if _, _, err := utils.ExecuteMigrationDefault(ctx, driverCtx, exec.store, driver, mi, schema, nil, db.ExecuteOptions{}); err != nil {
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index 23f9e79a9b..1e87365b50 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -8,7 +8,6 @@ import (
"log/slog"
"path/filepath"
"sort"
- "strconv"
"strings"
"github.com/gosimple/slug"
@@ -148,8 +147,7 @@ func getMigrationInfo(ctx context.Context, stores *store.Store, profile config.P
// Concat issue title and task name as the migration description so that user can see
// more context of the migration.
mi.Description = fmt.Sprintf("%s - %s", issue.Title, task.Name)
- mi.IssueID = strconv.Itoa(issue.UID)
- mi.IssueIDInt = &issue.UID
+ mi.IssueUID = &issue.UID
}
mi.Source = db.UI
diff --git a/backend/runner/taskrun/pitr_cutover_executor.go b/backend/runner/taskrun/pitr_cutover_executor.go
index 821d7f8ece..aaea7be4c6 100644
--- a/backend/runner/taskrun/pitr_cutover_executor.go
+++ b/backend/runner/taskrun/pitr_cutover_executor.go
@@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"log/slog"
- "strconv"
"time"
"github.com/gosimple/slug"
@@ -136,6 +135,7 @@ func (exec *PITRCutoverExecutor) pitrCutover(ctx context.Context, dbFactory *dbf
slog.Debug("Appending new migration history record")
m := &db.MigrationInfo{
InstanceID: &task.InstanceID,
+ IssueUID: &issue.UID,
ReleaseVersion: profile.Version,
Version: common.DefaultMigrationVersion(),
Namespace: database.DatabaseName,
@@ -148,7 +148,6 @@ func (exec *PITRCutoverExecutor) pitrCutover(ctx context.Context, dbFactory *dbf
Description: fmt.Sprintf("PITR: restoring database %s", database.DatabaseName),
Creator: creator.Name,
CreatorID: creator.ID,
- IssueID: strconv.Itoa(issue.UID),
}
driver, err := dbFactory.GetAdminDatabaseDriver(ctx, instance, database)
diff --git a/backend/runner/taskrun/pitr_restore_executor.go b/backend/runner/taskrun/pitr_restore_executor.go
index b9c5139fd1..5527cce465 100644
--- a/backend/runner/taskrun/pitr_restore_executor.go
+++ b/backend/runner/taskrun/pitr_restore_executor.go
@@ -8,7 +8,6 @@ import (
"os"
"path"
"path/filepath"
- "strconv"
"time"
"github.com/pkg/errors"
@@ -532,10 +531,6 @@ func createBranchMigrationHistory(ctx context.Context, stores *store.Store, dbFa
return "", model.Version{}, errors.Wrapf(err, "failed to fetch containing issue when creating the migration history: %v", task.Name)
}
// Add a branch migration history record.
- issueID := ""
- if issue != nil {
- issueID = strconv.Itoa(issue.UID)
- }
description := fmt.Sprintf("Restored from backup %q of database %q.", backup.Name, sourceDatabase.DatabaseName)
if sourceDatabase.InstanceID != targetDatabase.InstanceID {
description = fmt.Sprintf("Restored from backup %q of database %q in instance %q.", backup.Name, sourceDatabase.DatabaseName, sourceDatabase.InstanceID)
@@ -548,6 +543,7 @@ func createBranchMigrationHistory(ctx context.Context, stores *store.Store, dbFa
// TODO(d): support semantic versioning.
m := &db.MigrationInfo{
InstanceID: &task.InstanceID,
+ IssueUID: &issue.UID,
ReleaseVersion: profile.Version,
Version: common.DefaultMigrationVersion(),
Namespace: targetDatabase.DatabaseName,
@@ -559,7 +555,6 @@ func createBranchMigrationHistory(ctx context.Context, stores *store.Store, dbFa
Description: description,
Creator: creator.Name,
CreatorID: creator.ID,
- IssueID: issueID,
}
targetDriver, err := dbFactory.GetAdminDatabaseDriver(ctx, targetInstance, targetDatabase)
if err != nil {
diff --git a/backend/store/instance_change_history.go b/backend/store/instance_change_history.go
index 41656acf71..72e0fc4e42 100644
--- a/backend/store/instance_change_history.go
+++ b/backend/store/instance_change_history.go
@@ -84,22 +84,16 @@ type UpdateInstanceChangeHistoryMessage struct {
Sheet *int
}
-// CreateInstanceChangeHistory creates instance change history in batch.
-func (s *Store) CreateInstanceChangeHistory(ctx context.Context, create *InstanceChangeHistoryMessage) error {
+// CreateInstanceChangeHistoryForMigrator creates an instance change history for migrator.
+func (s *Store) CreateInstanceChangeHistoryForMigrator(ctx context.Context, create *InstanceChangeHistoryMessage) error {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()
- if create.InstanceUID == nil {
- if _, err := s.createInstanceChangeHistoryImplForMigrator(ctx, tx, create); err != nil {
- return err
- }
- } else {
- if _, err := s.createInstanceChangeHistoryImpl(ctx, tx, create); err != nil {
- return err
- }
+ if _, err := s.createInstanceChangeHistoryImplForMigrator(ctx, tx, create); err != nil {
+ return err
}
return tx.Commit()
}
@@ -726,7 +720,7 @@ func (s *Store) CreatePendingInstanceChangeHistory(ctx context.Context, prevSche
CreatorID: m.CreatorID,
InstanceUID: m.InstanceID,
DatabaseUID: m.DatabaseID,
- IssueUID: m.IssueIDInt,
+ IssueUID: m.IssueUID,
ReleaseVersion: m.ReleaseVersion,
Sequence: nextSequence,
Source: m.Source,
diff --git a/backend/utils/utils.go b/backend/utils/utils.go
index 08ce0ad929..f00583f38a 100644
--- a/backend/utils/utils.go
+++ b/backend/utils/utils.go
@@ -416,7 +416,11 @@ func ExecuteMigrationWithFunc(ctx context.Context, driverCtx context.Context, s
if common.ErrorCode(err) == common.MigrationAlreadyApplied {
return insertedID, prevSchemaBuf.String(), nil
}
- return "", "", errors.Wrapf(err, "failed to begin migration for issue %s", m.IssueID)
+ msg := "failed to begin migration"
+ if m.IssueUID != nil {
+ msg += fmt.Sprintf(" for issue %d", *m.IssueUID)
+ }
+ return "", "", errors.Wrapf(err, msg)
}
startedNs := time.Now().UnixNano()