Skip to content

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

fix: migrator (#12128)

Danny Xu47c896d6cb22
diff --git a/backend/migrator/migration/prod/2.18/0007##change_issue_project.sql b/backend/migrator/migration/prod/2.18/0007##change_issue_project.sql
index 2610a5c26a..f92217b14d 100644
--- a/backend/migrator/migration/prod/2.18/0007##change_issue_project.sql
+++ b/backend/migrator/migration/prod/2.18/0007##change_issue_project.sql
@@ -1,2 +1,2 @@
-ALTER TABLE instance_change_history ADD COLUMN project_id INTEGER REFERENCES project (id);
+ALTER TABLE instance_change_history ADD COLUMN IF NOT EXISTS project_id INTEGER REFERENCES project (id);
UPDATE instance_change_history SET project_id = (SELECT project_id FROM issue WHERE issue.id = instance_change_history.issue_id) WHERE instance_change_history.issue_id IS NOT NULL;
\ No newline at end of file
diff --git a/backend/migrator/migrator.go b/backend/migrator/migrator.go
index ae5cf84cf7..54a08a245f 100644
--- a/backend/migrator/migrator.go
+++ b/backend/migrator/migrator.go
@@ -54,6 +54,9 @@ func MigrateSchema(ctx context.Context, storeDB *store.DB, storeInstance *store.
if err := initializeSchema(ctx, storeInstance, metadataDriver, cutoffSchemaVersion, serverVersion); err != nil {
return nil, err
}
+ if _, err := metadataDriver.GetDB().ExecContext(ctx, "ALTER TABLE instance_change_history ADD COLUMN IF NOT EXISTS project_id INTEGER REFERENCES project (id);"); err != nil {
+ return nil, err
+ }
verBefore, err := getLatestVersion(ctx, storeInstance)
if err != nil {
diff --git a/backend/store/instance_change_history.go b/backend/store/instance_change_history.go
index 8ad688e10c..df3882e424 100644
--- a/backend/store/instance_change_history.go
+++ b/backend/store/instance_change_history.go
@@ -838,7 +838,6 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *
schemaPrevField = fmt.Sprintf("LEFT(%s, %d)", schemaPrevField, find.TruncateSize)
}
- // Project ID is not ready.
query := fmt.Sprintf(`
SELECT
instance_change_history.id,
@@ -849,6 +848,7 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *
instance_change_history.updated_ts,
instance_change_history.instance_id,
instance_change_history.database_id,
+ instance_change_history.project_id,
instance_change_history.issue_id,
instance_change_history.release_version,
instance_change_history.sequence,
@@ -891,7 +891,7 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *
for rows.Next() {
var changeHistory InstanceChangeHistoryMessage
var rowStatus, storedVersion, payload string
- var instanceID, databaseID, issueID sql.NullInt32
+ var instanceID, databaseID, projectID, issueID sql.NullInt32
if err := rows.Scan(
&changeHistory.UID,
&rowStatus,
@@ -901,6 +901,7 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *
&changeHistory.UpdatedTs,
&instanceID,
&databaseID,
+ &projectID,
&issueID,
&changeHistory.ReleaseVersion,
&changeHistory.Sequence,
@@ -927,6 +928,10 @@ func (s *Store) ListInstanceChangeHistoryForMigrator(ctx context.Context, find *
n := int(databaseID.Int32)
changeHistory.DatabaseUID = &n
}
+ if projectID.Valid {
+ n := int(projectID.Int32)
+ changeHistory.ProjectUID = &n
+ }
if issueID.Valid {
n := int(issueID.Int32)
changeHistory.IssueUID = &n