library-picturebook-activity/backend/sql/add_tenant_menu.sql
2025-11-23 14:04:20 +08:00

59 lines
1.7 KiB
SQL
Raw Permalink 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.

-- 为超级租户添加租户管理菜单
-- 注意需要先查询系统管理菜单的ID然后替换下面的 parent_id
-- 查询系统管理菜单的ID
-- SELECT id FROM menus WHERE name = '系统管理' AND parent_id IS NULL;
-- 假设系统管理菜单的ID为某个值需要根据实际情况调整
-- 这里使用子查询来动态获取系统管理菜单的ID
INSERT INTO menus (
name,
path,
icon,
component,
parent_id,
permission,
sort,
valid_state,
create_time,
modify_time
)
SELECT
'租户管理',
'/system/tenants',
'TeamOutlined',
'system/tenants/Index',
id, -- 系统管理菜单的ID
'tenant:read',
7, -- 排序,放在其他系统管理菜单之后
1,
NOW(),
NOW()
FROM menus
WHERE name = '系统管理' AND parent_id IS NULL
LIMIT 1;
-- 如果系统管理菜单不存在可以手动指定ID
-- INSERT INTO menus (name, path, icon, component, parent_id, permission, sort, valid_state, create_time, modify_time)
-- VALUES ('租户管理', '/system/tenants', 'TeamOutlined', 'system/tenants/Index', 2, 'tenant:read', 7, 1, NOW(), NOW());
-- 为超级租户分配租户管理菜单
-- 假设超级租户的ID为1需要根据实际情况调整
-- 假设租户管理菜单的ID为刚插入的菜单ID
INSERT INTO tenant_menus (tenant_id, menu_id)
SELECT
t.id AS tenant_id,
m.id AS menu_id
FROM tenants t
CROSS JOIN menus m
WHERE t.code = 'super' AND t.is_super = 1
AND m.name = '租户管理' AND m.path = '/system/tenants'
LIMIT 1;
-- 如果上面的查询没有结果可以手动指定ID
-- INSERT INTO tenant_menus (tenant_id, menu_id)
-- VALUES (1, (SELECT id FROM menus WHERE name = '租户管理' AND path = '/system/tenants' LIMIT 1));