Skip to content

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

chore: clean ghost sync tasks (#15245)

p0ny5e38810b1907
diff --git a/backend/migrator/migration/3.4/0016##clean_ghost.sql b/backend/migrator/migration/3.4/0016##clean_ghost.sql
new file mode 100644
index 0000000000..d093aca18b
--- /dev/null
+++ b/backend/migrator/migration/3.4/0016##clean_ghost.sql
@@ -0,0 +1,37 @@
+WITH t1 AS (
+ SELECT
+ to_task.id AS cutover_task_id,
+ from_task.payload AS sync_task_payload
+ FROM task_dag
+ LEFT JOIN task from_task ON from_task.id = task_dag.from_task_id
+ LEFT JOIN task to_task ON to_task.id = task_dag.to_task_id
+ WHERE to_task.type = 'bb.task.database.schema.update.ghost.cutover'
+)
+UPDATE task
+SET payload = t1.sync_task_payload
+FROM t1
+WHERE id = t1.cutover_task_id;
+
+DELETE FROM task_run_log
+USING task_run, task
+WHERE task_run_log.task_run_id = task_run.id AND task_run.task_id = task.id AND task.type = 'bb.task.database.schema.update.ghost.sync';
+
+DELETE FROM task_run
+USING task
+WHERE task.id = task_run.task_id AND task.type = 'bb.task.database.schema.update.ghost.sync';
+
+DELETE FROM task_dag
+USING task
+WHERE task_dag.from_task_id = task.id AND task.type = 'bb.task.database.schema.update.ghost.sync';
+
+DELETE FROM task
+WHERE task.type = 'bb.task.database.schema.update.ghost.sync';
+
+UPDATE task
+SET type = 'bb.task.database.schema.update-ghost'
+WHERE task.type = 'bb.task.database.schema.update.ghost.cutover';
+
+UPDATE task_run
+SET status = 'CANCELED'
+FROM task
+WHERE task.id = task_run.task_id AND task.type = 'bb.task.database.schema.update-ghost' AND task_run.status IN ('PENDING', 'RUNNING');
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 1c3717020b..9850deba50 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -212,5 +212,5 @@ func TestMigrationCompatibility(t *testing.T) {
func TestGetCutoffVersion(t *testing.T) {
releaseVersion, err := getProdCutoffVersion()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.4.15"), releaseVersion)
+ require.Equal(t, semver.MustParse("3.4.16"), releaseVersion)
}