From a934abe7aab5545e03e4d7028ecf725de991134a Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Wed, 24 Jun 2026 15:19:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E4=BF=AE=E5=A4=8D=20sourcemap=20?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=A0=E5=94=AF=E4=B8=80=E7=BA=A6=E6=9D=9F?= =?UTF-8?q?=E7=BC=BA=E5=B0=91=20build=5Fid=20=E5=AF=BC=E8=87=B4=20HTTP=205?= =?UTF-8?q?00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uk_map 约束为 (app_key, platform, app_version, bundle_name),未包含 build_id。Gradle 插件每次构建生成不同 buildId,服务端查不到记录后尝试 INSERT,触发 Duplicate entry 约束冲突返回 500。 V8 migration:删除旧约束,重建为 (app_key, platform, app_version, build_id, bundle_name)。 MySQL UNIQUE 对 NULL 视为不相等,历史 build_id=NULL 记录不受影响; 应用层已通过 findByBuildIdIsNull 防止 NULL 记录重复插入。 Co-Authored-By: Claude Sonnet 4.6 --- .../db/migration/V8__sourcemap_uk_add_build_id.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 xuqm-bugcollect-service/src/main/resources/db/migration/V8__sourcemap_uk_add_build_id.sql diff --git a/xuqm-bugcollect-service/src/main/resources/db/migration/V8__sourcemap_uk_add_build_id.sql b/xuqm-bugcollect-service/src/main/resources/db/migration/V8__sourcemap_uk_add_build_id.sql new file mode 100644 index 0000000..3d4635b --- /dev/null +++ b/xuqm-bugcollect-service/src/main/resources/db/migration/V8__sourcemap_uk_add_build_id.sql @@ -0,0 +1,14 @@ +-- V8: Include build_id in log_sourcemaps unique constraint. +-- +-- Problem: uk_map was (app_key, platform, app_version, bundle_name). +-- When the Gradle plugin uploads mapping files with a per-build buildId, +-- each new build of the same version generates a different buildId and tries +-- to INSERT a new row, which violates the old constraint → HTTP 500. +-- +-- Fix: rebuild uk_map to include build_id. +-- MySQL treats NULLs as distinct in unique indexes, so legacy records +-- (build_id IS NULL) coexist without conflict. Application logic already +-- prevents duplicate NULL-buildId rows via findByAppKeyAndPlatformAndAppVersionAndBuildIdIsNullAndBundleName. + +ALTER TABLE log_sourcemaps DROP INDEX uk_map; +ALTER TABLE log_sourcemaps ADD UNIQUE KEY uk_map (app_key, platform, app_version, build_id, bundle_name);