-- 让所有角色都能看到 Dashboard 和 Desktop 菜单
-- Dashboard sort_order=1, Desktop sort_order=2
START TRANSACTION;

SET @dashboard_id := (SELECT menu_id FROM sys_menus WHERE menu_code = 'dashboard' LIMIT 1);
SET @desktop_id   := (SELECT menu_id FROM sys_menus WHERE menu_code = 'desktop' LIMIT 1);

-- 确保 sort_order 有序
UPDATE sys_menus SET sort_order = 1 WHERE menu_code = 'dashboard';
UPDATE sys_menus SET sort_order = 2 WHERE menu_code = 'desktop';

-- 为 role_id=1 (admin) 补充 desktop 权限
INSERT IGNORE INTO sys_role_menu_permissions (role_id, menu_id, granted_at)
SELECT 1, @desktop_id, NOW()
FROM DUAL
WHERE @desktop_id IS NOT NULL;

-- 为 role_id=2 (普通用户) 补充 dashboard 权限
INSERT IGNORE INTO sys_role_menu_permissions (role_id, menu_id, granted_at)
SELECT 2, @dashboard_id, NOW()
FROM DUAL
WHERE @dashboard_id IS NOT NULL;

COMMIT;
