Files
smart_grid_iot/database/migrations/20261007_device_menu_split_fix.sql
T

89 lines
3.9 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 设备域菜单拆分-恢复版:先恢复被误覆盖的 55/56/57(报修派单/维保派单/重置电工密码),
-- 再用空闲 id 58-60 创建设备域菜单。修复由 20261007_device_menu_split.sql 引入的覆盖事故。
BEGIN;
-- ------------------------------------------------------------
-- 1) 恢复 id=55 报修派单(原字段:parent=3 /dispatch/repair dispatch:repair)
-- ------------------------------------------------------------
UPDATE sys_menu SET
parent_id = 3,
menu_name = '报修派单',
menu_path = '/dispatch/repair',
component = 'dispatch/repair/index',
icon = 'ToolOutlined',
sort_order = 3,
menu_type = 2,
permission = 'dispatch:repair',
visible = 1
WHERE id = 55;
-- ------------------------------------------------------------
-- 2) 恢复 id=56 维保派单(原字段:parent=3 /dispatch/maintenance dispatch:maintenance)
-- ------------------------------------------------------------
UPDATE sys_menu SET
parent_id = 3,
menu_name = '维保派单',
menu_path = '/dispatch/maintenance',
component = 'dispatch/maintenance/index',
icon = 'ToolOutlined',
sort_order = 4,
menu_type = 2,
permission = 'dispatch:maintenance',
visible = 1
WHERE id = 56;
-- ------------------------------------------------------------
-- 3) 恢复 id=57 重置电工密码(原字段:parent=3 按钮权限 worker:reset-password)
-- ------------------------------------------------------------
UPDATE sys_menu SET
parent_id = 3,
menu_name = '重置电工密码',
menu_path = NULL,
component = NULL,
icon = NULL,
sort_order = 11,
menu_type = 3,
permission = 'worker:reset-password',
visible = 1
WHERE id = 57;
-- 清理误绑定的角色菜单:(1,57) 保留给 ADMIN(重置电工密码按钮),并确保绑定存在
-- (2,55)(2,56) 语义已随恢复回到报修/维保派单,保留即可,无需改动
INSERT INTO sys_role_menu (role_id, menu_id) VALUES (1, 57)
ON CONFLICT (role_id, menu_id) DO NOTHING;
-- ------------------------------------------------------------
-- 4) 设备监控(id=4):菜单项 → 目录(menu_type=2→1),保持 /device 与 device:list
-- ------------------------------------------------------------
UPDATE sys_menu SET menu_type = 1 WHERE id = 4 AND menu_type = 2;
-- ------------------------------------------------------------
-- 5) 设备域菜单使用空闲 id 58-60
-- ------------------------------------------------------------
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
(58, 4, '设备管理台账', '/device/equipment', 'device/equipment/index', 'MonitorOutlined', 1, 2, 'device:list', 1),
(59, NULL, '基础数据', '/base', NULL, 'DatabaseOutlined', 5, 1, 'base:list', 1),
(60, 59, '智电设备型号', '/base/smart-device', 'device/smart-device/index', 'ApartmentOutlined', 1, 2, 'device:model', 1)
ON CONFLICT (id) DO UPDATE SET
parent_id = EXCLUDED.parent_id,
menu_name = EXCLUDED.menu_name,
menu_path = EXCLUDED.menu_path,
component = EXCLUDED.component,
icon = EXCLUDED.icon,
sort_order = EXCLUDED.sort_order,
menu_type = EXCLUDED.menu_type,
permission = EXCLUDED.permission,
visible = EXCLUDED.visible;
-- ------------------------------------------------------------
-- 6) 角色-菜单绑定:ADMIN(role_id=1) 拥有 58-60;SALESMAN 不给设备/基础数据权限
-- ------------------------------------------------------------
INSERT INTO sys_role_menu (role_id, menu_id) VALUES
(1, 58), (1, 59), (1, 60)
ON CONFLICT (role_id, menu_id) DO NOTHING;
-- 重置序列(覆盖到 60,避免后续手动插入冲突)
SELECT setval('sys_menu_id_seq', GREATEST((SELECT MAX(id) FROM sys_menu), 60), true);
COMMIT;