From 3c94bd189cf57d5b77aa8df3471d9615dcf8673a Mon Sep 17 00:00:00 2001 From: Bohan-J Date: Fri, 24 Jul 2026 15:21:11 +0800 Subject: [PATCH] fix(migrations): resolve VCS prefix collision (213-215) and make chat_session_project idempotent (MUL-3772) The VCS migrations (#5006) merged concurrently with task_usage_authoritative_cost and chat_session_project (#5765, renumbered by #5868), colliding on numeric prefixes 213/214/215. Two problems result: 1. The migration lint (TestMigrationNumericPrefixesStayUniqueAfterLegacySet) fails on the duplicate prefixes, so main CI is red. 2. The dev deploy crashes. chat_session_project was first shipped as 213_chat_session_project, then renamed 213 -> 214 (#5868) to dodge the VCS collision. Environments that already applied it as 213 re-run it under the new 214 name, and because the ADD COLUMN was not idempotent it fails with "column project_id already exists" (SQLSTATE 42701), aborting startup. Fix: - Renumber the six VCS migrations off the collisions to a unique contiguous tail 216-221, preserving order (table creation at 216 before its indexes at 217-221). Every VCS migration is CREATE ... IF NOT EXISTS, so re-running them under the new names is a safe no-op on any environment that already applied the old 213-218 numbers. - Make 214_chat_session_project idempotent (ADD COLUMN IF NOT EXISTS) so the #5868 rename-induced re-run no-ops instead of crashing. Verified locally: the lint test passes; a fresh `migrate up` applies 213..221 in order; a DB seeded into the exact dev failure state (project_id column present, 214 version row absent) now re-applies 214 as a no-op and completes; `go build` and the VCS handler + migration tests pass. Co-authored-by: multica-agent --- server/migrations/214_chat_session_project.up.sql | 8 +++++++- ..._integration.down.sql => 216_vcs_integration.down.sql} | 0 ..._vcs_integration.up.sql => 216_vcs_integration.up.sql} | 0 ...wn.sql => 217_vcs_connection_workspace_index.down.sql} | 0 ...x.up.sql => 217_vcs_connection_workspace_index.up.sql} | 0 ....sql => 218_vcs_pull_request_workspace_index.down.sql} | 0 ...up.sql => 218_vcs_pull_request_workspace_index.up.sql} | 0 ...sql => 219_vcs_pull_request_connection_index.down.sql} | 0 ...p.sql => 219_vcs_pull_request_connection_index.up.sql} | 0 ...n.sql => 220_issue_vcs_pull_request_pr_index.down.sql} | 0 ....up.sql => 220_issue_vcs_pull_request_pr_index.up.sql} | 0 ...wn.sql => 221_vcs_commit_status_lookup_index.down.sql} | 0 ...x.up.sql => 221_vcs_commit_status_lookup_index.up.sql} | 0 13 files changed, 7 insertions(+), 1 deletion(-) rename server/migrations/{213_vcs_integration.down.sql => 216_vcs_integration.down.sql} (100%) rename server/migrations/{213_vcs_integration.up.sql => 216_vcs_integration.up.sql} (100%) rename server/migrations/{214_vcs_connection_workspace_index.down.sql => 217_vcs_connection_workspace_index.down.sql} (100%) rename server/migrations/{214_vcs_connection_workspace_index.up.sql => 217_vcs_connection_workspace_index.up.sql} (100%) rename server/migrations/{215_vcs_pull_request_workspace_index.down.sql => 218_vcs_pull_request_workspace_index.down.sql} (100%) rename server/migrations/{215_vcs_pull_request_workspace_index.up.sql => 218_vcs_pull_request_workspace_index.up.sql} (100%) rename server/migrations/{216_vcs_pull_request_connection_index.down.sql => 219_vcs_pull_request_connection_index.down.sql} (100%) rename server/migrations/{216_vcs_pull_request_connection_index.up.sql => 219_vcs_pull_request_connection_index.up.sql} (100%) rename server/migrations/{217_issue_vcs_pull_request_pr_index.down.sql => 220_issue_vcs_pull_request_pr_index.down.sql} (100%) rename server/migrations/{217_issue_vcs_pull_request_pr_index.up.sql => 220_issue_vcs_pull_request_pr_index.up.sql} (100%) rename server/migrations/{218_vcs_commit_status_lookup_index.down.sql => 221_vcs_commit_status_lookup_index.down.sql} (100%) rename server/migrations/{218_vcs_commit_status_lookup_index.up.sql => 221_vcs_commit_status_lookup_index.up.sql} (100%) diff --git a/server/migrations/214_chat_session_project.up.sql b/server/migrations/214_chat_session_project.up.sql index 880d4f67d..86db0e7cf 100644 --- a/server/migrations/214_chat_session_project.up.sql +++ b/server/migrations/214_chat_session_project.up.sql @@ -4,5 +4,11 @@ -- Create/delete handlers serialize on the project row, project deletion clears -- existing references, and daemon claim revalidates workspace ownership before -- injecting any context. +-- +-- IF NOT EXISTS because this migration was first shipped as 213_chat_session_project +-- and later renumbered to 214 (#5868, dodging a prefix collision). Environments +-- that already applied it under the old 213 name have the column but not the 214 +-- version row, so the runner re-applies it under the new name; without the guard +-- that re-run fails with "column already exists" (SQLSTATE 42701) and blocks deploy. ALTER TABLE chat_session - ADD COLUMN project_id UUID; + ADD COLUMN IF NOT EXISTS project_id UUID; diff --git a/server/migrations/213_vcs_integration.down.sql b/server/migrations/216_vcs_integration.down.sql similarity index 100% rename from server/migrations/213_vcs_integration.down.sql rename to server/migrations/216_vcs_integration.down.sql diff --git a/server/migrations/213_vcs_integration.up.sql b/server/migrations/216_vcs_integration.up.sql similarity index 100% rename from server/migrations/213_vcs_integration.up.sql rename to server/migrations/216_vcs_integration.up.sql diff --git a/server/migrations/214_vcs_connection_workspace_index.down.sql b/server/migrations/217_vcs_connection_workspace_index.down.sql similarity index 100% rename from server/migrations/214_vcs_connection_workspace_index.down.sql rename to server/migrations/217_vcs_connection_workspace_index.down.sql diff --git a/server/migrations/214_vcs_connection_workspace_index.up.sql b/server/migrations/217_vcs_connection_workspace_index.up.sql similarity index 100% rename from server/migrations/214_vcs_connection_workspace_index.up.sql rename to server/migrations/217_vcs_connection_workspace_index.up.sql diff --git a/server/migrations/215_vcs_pull_request_workspace_index.down.sql b/server/migrations/218_vcs_pull_request_workspace_index.down.sql similarity index 100% rename from server/migrations/215_vcs_pull_request_workspace_index.down.sql rename to server/migrations/218_vcs_pull_request_workspace_index.down.sql diff --git a/server/migrations/215_vcs_pull_request_workspace_index.up.sql b/server/migrations/218_vcs_pull_request_workspace_index.up.sql similarity index 100% rename from server/migrations/215_vcs_pull_request_workspace_index.up.sql rename to server/migrations/218_vcs_pull_request_workspace_index.up.sql diff --git a/server/migrations/216_vcs_pull_request_connection_index.down.sql b/server/migrations/219_vcs_pull_request_connection_index.down.sql similarity index 100% rename from server/migrations/216_vcs_pull_request_connection_index.down.sql rename to server/migrations/219_vcs_pull_request_connection_index.down.sql diff --git a/server/migrations/216_vcs_pull_request_connection_index.up.sql b/server/migrations/219_vcs_pull_request_connection_index.up.sql similarity index 100% rename from server/migrations/216_vcs_pull_request_connection_index.up.sql rename to server/migrations/219_vcs_pull_request_connection_index.up.sql diff --git a/server/migrations/217_issue_vcs_pull_request_pr_index.down.sql b/server/migrations/220_issue_vcs_pull_request_pr_index.down.sql similarity index 100% rename from server/migrations/217_issue_vcs_pull_request_pr_index.down.sql rename to server/migrations/220_issue_vcs_pull_request_pr_index.down.sql diff --git a/server/migrations/217_issue_vcs_pull_request_pr_index.up.sql b/server/migrations/220_issue_vcs_pull_request_pr_index.up.sql similarity index 100% rename from server/migrations/217_issue_vcs_pull_request_pr_index.up.sql rename to server/migrations/220_issue_vcs_pull_request_pr_index.up.sql diff --git a/server/migrations/218_vcs_commit_status_lookup_index.down.sql b/server/migrations/221_vcs_commit_status_lookup_index.down.sql similarity index 100% rename from server/migrations/218_vcs_commit_status_lookup_index.down.sql rename to server/migrations/221_vcs_commit_status_lookup_index.down.sql diff --git a/server/migrations/218_vcs_commit_status_lookup_index.up.sql b/server/migrations/221_vcs_commit_status_lookup_index.up.sql similarity index 100% rename from server/migrations/218_vcs_commit_status_lookup_index.up.sql rename to server/migrations/221_vcs_commit_status_lookup_index.up.sql