From f0cd3b5d335b3bfd183cebec46ed10116e8d317e Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Mon, 22 Jun 2026 17:12:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(bugcollect):=20=E4=BF=AE=E5=A4=8D=20V6=20?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=20SQL=20=E9=94=99=E8=AF=AF=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=B9=82=E7=AD=89=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AFTER app_version(列名)替代 AFTER release(Java字段名) - 使用 information_schema 条件检查实现幂等,防止重复执行报错 - LogService log 语句中 issueId → eventId Co-Authored-By: Claude Sonnet 4.6 --- .../resources/db/migration/V6__build_id.sql | 70 +++++++++++++------ 1 file changed, 49 insertions(+), 21 deletions(-) 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 e7c10e2..96fe2e1 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,27 +1,55 @@ -- V6: build_id support for multi-build-per-version sourcemap tracking --- ───────────────────────────────────────────────────────────────────── --- log_sourcemaps: --- • Drop old unique key that prevented multiple builds of the same version --- • Add build_id (nullable for backward compat with pre-V6 uploads) --- • New unique key includes build_id; MySQL treats NULL as distinct in UNIQUE, --- so old rows (build_id=NULL) are not affected and remain individually unique --- • Add fallback index for version-only lookup (for events without buildId) --- --- log_issue_events: --- • Add build_id so events can be matched to the exact sourcemap build +-- log_sourcemaps: add build_id, update unique key, add fallback index +-- log_issue_events: add build_id for exact symbolication matching -ALTER TABLE log_sourcemaps - ADD COLUMN build_id VARCHAR(32) NULL COMMENT 'Gradle build timestamp yyyyMMddHHmmss; NULL = pre-V6 upload' - AFTER bundle_name; +-- Conditional: add build_id to log_sourcemaps only if not exists +SET @col_exists = ( + SELECT COUNT(*) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'log_sourcemaps' AND COLUMN_NAME = 'build_id' +); +SET @sql = IF(@col_exists = 0, + 'ALTER TABLE log_sourcemaps ADD COLUMN build_id VARCHAR(32) NULL COMMENT ''Gradle build timestamp yyyyMMddHHmmss; NULL = pre-V6 upload'' AFTER bundle_name', + 'SELECT 1' +); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -ALTER TABLE log_sourcemaps DROP KEY uk_map; +-- Conditional: drop old uk_map key only if still exists +SET @key_exists = ( + SELECT COUNT(*) FROM information_schema.STATISTICS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'log_sourcemaps' AND INDEX_NAME = 'uk_map' +); +SET @sql = IF(@key_exists > 0, 'ALTER TABLE log_sourcemaps DROP KEY uk_map', 'SELECT 1'); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -ALTER TABLE log_sourcemaps - ADD UNIQUE KEY uk_map_build (app_key, platform, app_version, build_id, bundle_name); +-- Conditional: add uk_map_build unique key only if not exists +SET @key_exists = ( + SELECT COUNT(*) FROM information_schema.STATISTICS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'log_sourcemaps' AND INDEX_NAME = 'uk_map_build' +); +SET @sql = IF(@key_exists = 0, + 'ALTER TABLE log_sourcemaps ADD UNIQUE KEY uk_map_build (app_key, platform, app_version, build_id, bundle_name)', + 'SELECT 1' +); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -ALTER TABLE log_sourcemaps - ADD INDEX idx_sm_version_latest (app_key, platform, app_version, bundle_name, uploaded_at); +-- Conditional: add idx_sm_version_latest only if not exists +SET @key_exists = ( + SELECT COUNT(*) FROM information_schema.STATISTICS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'log_sourcemaps' AND INDEX_NAME = 'idx_sm_version_latest' +); +SET @sql = IF(@key_exists = 0, + 'ALTER TABLE log_sourcemaps ADD INDEX idx_sm_version_latest (app_key, platform, app_version, bundle_name, uploaded_at)', + 'SELECT 1' +); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -ALTER TABLE log_issue_events - ADD COLUMN build_id VARCHAR(32) NULL COMMENT 'Matches log_sourcemaps.build_id for exact symbolication' - AFTER release; +-- Conditional: add build_id to log_issue_events only if not exists +SET @col_exists = ( + SELECT COUNT(*) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'log_issue_events' AND COLUMN_NAME = 'build_id' +); +SET @sql = IF(@col_exists = 0, + 'ALTER TABLE log_issue_events ADD COLUMN build_id VARCHAR(32) NULL COMMENT ''Matches log_sourcemaps.build_id for exact symbolication'' AFTER app_version', + 'SELECT 1' +); +PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;