From 84c4a0c7c750bf8ac87d40fbf4071ff6ac0fc7e2 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期四, 03 九月 2026 17:53:23 +0800
Subject: [PATCH] 修复测试预警异常迁移校验

---
 ruoyi-admin/src/main/resources/db/migration/V41__test_warning_exceptions.sql                |    3 +--
 ruoyi-admin/src/main/resources/db/migration/V42__test_warning_exception_open_uniqueness.sql |    6 ++++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ruoyi-admin/src/main/resources/db/migration/V41__test_warning_exceptions.sql b/ruoyi-admin/src/main/resources/db/migration/V41__test_warning_exceptions.sql
index b4dddf6..f19690b 100644
--- a/ruoyi-admin/src/main/resources/db/migration/V41__test_warning_exceptions.sql
+++ b/ruoyi-admin/src/main/resources/db/migration/V41__test_warning_exceptions.sql
@@ -17,7 +17,6 @@
     handled_at_utc DATETIME(3) NULL,
     handling_note VARCHAR(1000) NULL,
     PRIMARY KEY (exception_id),
-    open_threshold_id BIGINT GENERATED ALWAYS AS (IF(exception_status = 'OPEN', threshold_id, NULL)) STORED,
-    UNIQUE KEY uk_warning_exception_open (test_id, metric_code, open_threshold_id),
+    UNIQUE KEY uk_warning_exception_open (test_id, metric_code, threshold_id, exception_status),
     KEY idx_warning_exception_query (test_id, exception_status, last_occurred_at_utc)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='测试预警阈值异常';
diff --git a/ruoyi-admin/src/main/resources/db/migration/V42__test_warning_exception_open_uniqueness.sql b/ruoyi-admin/src/main/resources/db/migration/V42__test_warning_exception_open_uniqueness.sql
new file mode 100644
index 0000000..1ff6d41
--- /dev/null
+++ b/ruoyi-admin/src/main/resources/db/migration/V42__test_warning_exception_open_uniqueness.sql
@@ -0,0 +1,6 @@
+ALTER TABLE t_test_warning_exception
+    DROP INDEX uk_warning_exception_open,
+    ADD COLUMN open_threshold_id BIGINT GENERATED ALWAYS AS (
+        IF(exception_status = 'OPEN', threshold_id, NULL)
+    ) STORED AFTER exception_status,
+    ADD UNIQUE KEY uk_warning_exception_open (test_id, metric_code, open_threshold_id);

--
Gitblit v1.7.1