From e294d42dff76e4788699071ca1f1330155001c39 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Tue, 23 Jun 2026 18:53:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(bugcollect):=20=E4=BF=AE=E5=A4=8D=20V6=20no?= =?UTF-8?q?-op=20=E5=AF=BC=E8=87=B4=20build=5Fid=20=E5=88=97=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E5=BC=95=E5=8F=91=E7=9A=84=20502?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V6 迁移原为空操作(SELECT 1),导致 log_issue_events 和 log_sourcemaps 表缺少 build_id 列,服务启动时 Hibernate schema 校验失败并持续重启。 - 重写 V6 为实际 DDL(ALTER TABLE ... ADD COLUMN build_id) - 新增 V7 幂等修复迁移,使用条件预处理语句,对已有列的部署安全跳过 Co-Authored-By: Claude Sonnet 4.6 --- .../resources/db/migration/V6__build_id.sql | 22 ++++++++++++-- .../db/migration/V7__build_id_repair.sql | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 xuqm-bugcollect-service/src/main/resources/db/migration/V7__build_id_repair.sql diff --git a/xuqm-bugcollect-service/src/main/resources/db/migration/V6__build_id.sql b/xuqm-bugcollect-service/src/main/resources/db/migration/V6__build_id.sql index 6008141..93315bb 100644 --- a/xuqm-bugcollect-service/src/main/resources/db/migration/V6__build_id.sql +++ b/xuqm-bugcollect-service/src/main/resources/db/migration/V6__build_id.sql @@ -1,4 +1,20 @@ -- V6: build_id support for multi-build-per-version sourcemap tracking --- All DDL was applied manually during the initial migration incident. --- This script is intentionally a no-op to let Flyway record V6 as done. -SELECT 1; +-- +-- Adds build_id to log_issue_events and log_sourcemaps so each unique +-- (appKey, platform, appVersion, buildId, bundleName) combination can +-- store its own sourcemap file without overwriting sibling builds. +-- +-- Existing deployments where this column was already added manually: +-- Flyway will have recorded V6 as done via the old no-op; those databases +-- have the column already. For any deployment where V6 ran as a no-op +-- and the column is still missing, run the repair migration V7. + +ALTER TABLE log_issue_events + ADD COLUMN build_id VARCHAR(32) NULL + COMMENT 'Build identifier for sourcemap tracking' + AFTER app_version; + +ALTER TABLE log_sourcemaps + ADD COLUMN build_id VARCHAR(32) NULL + COMMENT 'Build identifier for multi-build-per-version sourcemap tracking' + AFTER app_version; diff --git a/xuqm-bugcollect-service/src/main/resources/db/migration/V7__build_id_repair.sql b/xuqm-bugcollect-service/src/main/resources/db/migration/V7__build_id_repair.sql new file mode 100644 index 0000000..8bac0eb --- /dev/null +++ b/xuqm-bugcollect-service/src/main/resources/db/migration/V7__build_id_repair.sql @@ -0,0 +1,30 @@ +-- V7: repair for deployments where V6 ran as a no-op +-- +-- On some deployments V6 was recorded as done but contained only SELECT 1, +-- leaving build_id missing from log_issue_events and log_sourcemaps. +-- This migration adds the column idempotently using a prepared statement so +-- it is safe whether the column already exists or not. + +SET @_add_lie = IF( + NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = DATABASE() + AND table_name = 'log_issue_events' + AND column_name = 'build_id' + ), + 'ALTER TABLE log_issue_events ADD COLUMN build_id VARCHAR(32) NULL COMMENT ''Build identifier for sourcemap tracking'' AFTER app_version', + 'SELECT 1 /* log_issue_events.build_id already exists */' +); +PREPARE _s FROM @_add_lie; EXECUTE _s; DEALLOCATE PREPARE _s; + +SET @_add_lsm = IF( + NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_schema = DATABASE() + AND table_name = 'log_sourcemaps' + AND column_name = 'build_id' + ), + 'ALTER TABLE log_sourcemaps ADD COLUMN build_id VARCHAR(32) NULL COMMENT ''Build identifier for multi-build-per-version sourcemap tracking'' AFTER app_version', + 'SELECT 1 /* log_sourcemaps.build_id already exists */' +); +PREPARE _s FROM @_add_lsm; EXECUTE _s; DEALLOCATE PREPARE _s;