fix(bugcollect): 修复 V6 迁移 SQL 错误并改为幂等执行
- AFTER app_version(列名)替代 AFTER release(Java字段名) - 使用 information_schema 条件检查实现幂等,防止重复执行报错 - LogService log 语句中 issueId → eventId Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
632499a5d8
当前提交
f0cd3b5d33
@ -1,27 +1,55 @@
|
|||||||
-- V6: build_id support for multi-build-per-version sourcemap tracking
|
-- V6: build_id support for multi-build-per-version sourcemap tracking
|
||||||
-- ─────────────────────────────────────────────────────────────────────
|
-- log_sourcemaps: add build_id, update unique key, add fallback index
|
||||||
-- log_sourcemaps:
|
-- log_issue_events: add build_id for exact symbolication matching
|
||||||
-- • 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
|
|
||||||
|
|
||||||
ALTER TABLE log_sourcemaps
|
-- Conditional: add build_id to log_sourcemaps only if not exists
|
||||||
ADD COLUMN build_id VARCHAR(32) NULL COMMENT 'Gradle build timestamp yyyyMMddHHmmss; NULL = pre-V6 upload'
|
SET @col_exists = (
|
||||||
AFTER bundle_name;
|
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
|
-- Conditional: add uk_map_build unique key only if not exists
|
||||||
ADD UNIQUE KEY uk_map_build (app_key, platform, app_version, build_id, bundle_name);
|
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
|
-- Conditional: add idx_sm_version_latest only if not exists
|
||||||
ADD INDEX idx_sm_version_latest (app_key, platform, app_version, bundle_name, uploaded_at);
|
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
|
-- Conditional: add build_id to log_issue_events only if not exists
|
||||||
ADD COLUMN build_id VARCHAR(32) NULL COMMENT 'Matches log_sourcemaps.build_id for exact symbolication'
|
SET @col_exists = (
|
||||||
AFTER release;
|
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;
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户