fix(bugcollect): 修复 V6 no-op 导致 build_id 列缺失引发的 502

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 <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-06-23 18:53:57 +08:00
父节点 ddaf2829cc
当前提交 e294d42dff
共有 2 个文件被更改,包括 49 次插入3 次删除

查看文件

@ -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;

查看文件

@ -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;