refactor: 统一数据库约束维护位置
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
-- base_sys_user_role 角色授权去重
|
||||
-- 只处理未软删除的有效授权;软删除历史记录不参与去重和唯一约束
|
||||
-- 只处理未软删除的有效授权;软删除历史记录不参与去重
|
||||
-- 保留每组有效 userId + roleId 中 id 最小的一条,删除其余重复记录
|
||||
|
||||
-- 1. 执行前查看重复数据
|
||||
@@ -34,12 +34,4 @@ WHERE deleted_at IS NULL
|
||||
GROUP BY "userId", "roleId"
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
-- 4. 建议约束:只限制未软删除授权唯一,允许历史软删除授权保留
|
||||
ALTER TABLE base_sys_user_role
|
||||
DROP CONSTRAINT IF EXISTS uk_base_sys_user_role_user_role;
|
||||
|
||||
DROP INDEX IF EXISTS uk_base_sys_user_role_user_role;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uk_base_sys_user_role_user_role
|
||||
ON base_sys_user_role ("userId", "roleId")
|
||||
WHERE deleted_at IS NULL;
|
||||
-- 唯一约束统一在 约束类.sql 中维护。
|
||||
|
||||
Reference in New Issue
Block a user