diff --git a/xuqm-bugcollect-service/src/main/resources/db/migration/V4__bugcollect_v12.sql b/xuqm-bugcollect-service/src/main/resources/db/migration/V4__bugcollect_v12.sql index 10c33bb..fec103c 100644 --- a/xuqm-bugcollect-service/src/main/resources/db/migration/V4__bugcollect_v12.sql +++ b/xuqm-bugcollect-service/src/main/resources/db/migration/V4__bugcollect_v12.sql @@ -1,7 +1,9 @@ -- V4: log_issue_users dedup table, secret on log_webhooks, log_sessions skeleton -- ────────────────────────────────────────────────────────────────────────────── +-- MySQL 兼容:不使用 ADD COLUMN IF NOT EXISTS / ADD INDEX IF NOT EXISTS +-- 全新部署时顺序执行无问题;升级场景若部分执行过,需手动修复 flyway_history_log --- Dedup table for affectedUsers counting (one row per issue × user) +-- 1) Dedup table for affectedUsers counting (one row per issue × user) CREATE TABLE IF NOT EXISTS log_issue_users ( issue_id BIGINT NOT NULL, user_id VARCHAR(128) NOT NULL, @@ -10,14 +12,7 @@ CREATE TABLE IF NOT EXISTS log_issue_users ( INDEX idx_liu_issue_id (issue_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; --- HMAC signing secret for webhooks (nullable = no signing) --- MySQL does not support ADD COLUMN IF NOT EXISTS. --- If the column already exists (e.g. partial re-run), this migration will fail. --- V5__bugcollect_v12_repair.sql handles the repair case. -ALTER TABLE log_webhooks - ADD COLUMN secret VARCHAR(64) NULL COMMENT 'HMAC-SHA256 signing secret; NULL = no signature'; - --- Session tracking table (ingestion path via /sessions/batch is not yet implemented) +-- 2) Session tracking table (ingestion path via /sessions/batch is not yet implemented) CREATE TABLE IF NOT EXISTS log_sessions ( id BIGINT NOT NULL AUTO_INCREMENT, app_key VARCHAR(64) NOT NULL, @@ -36,6 +31,3 @@ CREATE TABLE IF NOT EXISTS log_sessions ( INDEX idx_ls_app_key (app_key), INDEX idx_ls_started_at (started_at) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - --- Ensure event_id has an index (was added as NULL in V3) -CREATE INDEX idx_lie_event_id ON log_issue_events (event_id); diff --git a/xuqm-bugcollect-service/src/main/resources/db/migration/V5__bugcollect_v12_part2.sql b/xuqm-bugcollect-service/src/main/resources/db/migration/V5__bugcollect_v12_part2.sql new file mode 100644 index 0000000..1b77305 --- /dev/null +++ b/xuqm-bugcollect-service/src/main/resources/db/migration/V5__bugcollect_v12_part2.sql @@ -0,0 +1,18 @@ +-- V5: bugcollect v12 part 2 — ALTER TABLE / CREATE INDEX +-- ───────────────────────────────────────────────────────── +-- 分离到 V5 是因为 MySQL 不支持 ADD COLUMN IF NOT EXISTS / ADD INDEX IF NOT EXISTS。 +-- 全新部署:V4 + V5 顺序执行,全部成功。 +-- 升级场景:若 V4 部分执行过(secret 列已存在),需手动修复: +-- 1) docker exec mysql mysql -uxuqm -p'...' xuqm_bugcollect +-- DELETE FROM flyway_history_log WHERE version IN (4,5); +-- ALTER TABLE log_webhooks ADD COLUMN IF NOT EXISTS secret VARCHAR(64) NULL; +-- CREATE INDEX IF NOT EXISTS idx_lie_event_id ON log_issue_events (event_id); +-- INSERT INTO flyway_history_log (...) VALUES (4, ...), (5, ...); +-- 2) docker restart bugcollect-service + +-- HMAC signing secret for webhooks (nullable = no signing) +ALTER TABLE log_webhooks + ADD COLUMN secret VARCHAR(64) NULL COMMENT 'HMAC-SHA256 signing secret; NULL = no signature'; + +-- Ensure event_id has an index (was added as NULL in V3) +CREATE INDEX idx_lie_event_id ON log_issue_events (event_id);