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:
30
help/base_sys_user_role去重.sql
Normal file
30
help/base_sys_user_role去重.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- base_sys_user_role 角色授权去重
|
||||
-- 保留每组 userId + roleId 中 id 最小的一条,删除其余重复记录
|
||||
|
||||
-- 1. 执行前查看重复数据
|
||||
SELECT
|
||||
"userId",
|
||||
"roleId",
|
||||
COUNT(*) AS cnt,
|
||||
MIN(id) AS keep_id,
|
||||
ARRAY_AGG(id ORDER BY id) AS ids
|
||||
FROM base_sys_user_role
|
||||
GROUP BY "userId", "roleId"
|
||||
HAVING COUNT(*) > 1
|
||||
ORDER BY cnt DESC, "userId", "roleId";
|
||||
|
||||
-- 2. 删除重复数据
|
||||
DELETE FROM base_sys_user_role a
|
||||
USING base_sys_user_role b
|
||||
WHERE a."userId" = b."userId"
|
||||
AND a."roleId" = b."roleId"
|
||||
AND a.id > b.id;
|
||||
|
||||
-- 3. 执行后复查,应返回 0 行
|
||||
SELECT
|
||||
"userId",
|
||||
"roleId",
|
||||
COUNT(*) AS cnt
|
||||
FROM base_sys_user_role
|
||||
GROUP BY "userId", "roleId"
|
||||
HAVING COUNT(*) > 1;
|
||||
13
help/约束类.sql
13
help/约束类.sql
@@ -39,4 +39,15 @@ WHERE deleted_at IS NULL;
|
||||
--房间索引
|
||||
CREATE UNIQUE INDEX uk_player_room_house
|
||||
ON player_room_house (player_id, is_vip)
|
||||
WHERE deleted_at IS NULL;
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
-- 集市权限角色 联合唯一
|
||||
-- 先清理历史重复授权,保留每组 userId + roleId 中 id 最小的一条
|
||||
DELETE FROM base_sys_user_role a
|
||||
USING base_sys_user_role b
|
||||
WHERE a."userId" = b."userId"
|
||||
AND a."roleId" = b."roleId"
|
||||
AND a.id > b.id;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uk_base_sys_user_role_user_role
|
||||
ON base_sys_user_role ("userId", "roleId");
|
||||
|
||||
Reference in New Issue
Block a user