fix(db): 修复010验收脚本的V2唯一约束范围与索引表达式兼容性

This commit is contained in:
wangzhibiao committed 2026-09-14 02:41:55 +08:00
1 parent 4beff4c360
commit 487583c2aa
1 file changed
+9 -5
+9 -5
View File
@@ -152,6 +152,7 @@ BEGIN
WHERE tc.constraint_type = 'UNIQUE'
AND tc.table_schema = 'public'
AND tc.table_name LIKE 'train_%'
AND tc.constraint_name LIKE 'uq_%'
GROUP BY tc.table_name, tc.constraint_name
)
SELECT 'MISSING_UQ' AS diff_type, e.table_name, e.constraint_name, e.column_list
@@ -384,27 +385,30 @@ BEGIN
AND tablename = 'train_study_duration'
AND indexname = 'uq_idx_study_source_event'
AND indexdef LIKE '%UNIQUE INDEX%'
AND indexdef LIKE '%(source_system, source_event_id)%'
AND (indexdef LIKE '%(source_system, source_event_id)%' OR (indexdef LIKE '%source_system%source_event_id%'))
AND indexdef LIKE '%source_system IS NOT NULL%'
AND indexdef LIKE '%source_event_id IS NOT NULL%';
IF v_cnt <> 1 THEN
RAISE EXCEPTION '>>> [Verify-FATAL] 部分唯一索引 uq_idx_study_source_event 定义不合要求';
END IF;
-- 7.2 排课表三大时间检索复合索引
-- 7.2 排课表三大时间检索复合索引 (兼容 Kingbase 索引生成的 NULLS FIRST 表达式格式)
SELECT count(*) INTO v_cnt FROM pg_indexes
WHERE schemaname = 'public' AND tablename = 'train_lesson'
AND indexname = 'idx_lesson_teacher_time' AND indexdef LIKE '%(t_id, start_time, end_time)%';
AND indexname = 'idx_lesson_teacher_time'
AND (indexdef LIKE '%(t_id, start_time, end_time)%' OR indexdef LIKE '%t_id%start_time%end_time%');
IF v_cnt <> 1 THEN RAISE EXCEPTION '>>> [Verify-FATAL] 索引 idx_lesson_teacher_time 复合列定义不合要求'; END IF;
SELECT count(*) INTO v_cnt FROM pg_indexes
WHERE schemaname = 'public' AND tablename = 'train_lesson'
AND indexname = 'idx_lesson_classroom_time' AND indexdef LIKE '%(class_room_id, start_time, end_time)%';
AND indexname = 'idx_lesson_classroom_time'
AND (indexdef LIKE '%(class_room_id, start_time, end_time)%' OR indexdef LIKE '%class_room_id%start_time%end_time%');
IF v_cnt <> 1 THEN RAISE EXCEPTION '>>> [Verify-FATAL] 索引 idx_lesson_classroom_time 复合列定义不合要求'; END IF;
SELECT count(*) INTO v_cnt FROM pg_indexes
WHERE schemaname = 'public' AND tablename = 'train_lesson'
AND indexname = 'idx_lesson_site_time' AND indexdef LIKE '%(site_id, start_time, end_time)%';
AND indexname = 'idx_lesson_site_time'
AND (indexdef LIKE '%(site_id, start_time, end_time)%' OR indexdef LIKE '%site_id%start_time%end_time%');
IF v_cnt <> 1 THEN RAISE EXCEPTION '>>> [Verify-FATAL] 索引 idx_lesson_site_time 复合列定义不合要求'; END IF;
-- ==========================================================================