Files
smart-go/migrations/postgres/006_seed_iam_menu_full.sql
T
2026-04-23 18:58:13 +08:00

210 lines
4.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.
-- 全量业务菜单种子(与当前后端能力对齐:IAM 租户/部门/角色/用户/菜单 + System 参数)
-- 依赖:001_iam.sql;建议在 004_seed_platform_builtin.sql 之后执行(以便角色已存在时可挂接权限)
--
-- 约定:
-- menu_type: 1=目录 2=菜单 3=按钮(本脚本仅录入目录+菜单,便于侧栏 /nav)
-- 「概览」(/dashboard) 不入库:全员可进,由前端壳层固定展示,不参与 iam_menu 配置与角色授权
-- path 与 Next 管理端路由对齐(可按实际前端调整)
--
-- 固定菜单 id 前缀 31000000-0000-4000-8000-* 便于识别与文档引用
BEGIN;
INSERT INTO iam_menu (
id, parent_id, menu_name, menu_type, perms, path, component, icon, sort_order,
is_visible, is_builtin, status, created_at, updated_at
) VALUES
-- 工作台(目录)
(
'31000000-0000-4000-8000-000000000001',
'',
'工作台',
1,
'workspace:root',
'',
'',
'',
10,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000003',
'31000000-0000-4000-8000-000000000001',
'个人中心',
2,
'account:profile',
'/dashboard/account',
'',
'👤',
20,
true,
true,
1,
now(),
now()
),
-- 系统:/api/v1/system/param/*
(
'31000000-0000-4000-8000-000000000010',
'',
'系统管理',
1,
'system:module',
'',
'',
'',
40,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000011',
'31000000-0000-4000-8000-000000000010',
'参数配置',
2,
'system:param:list',
'/dashboard/system/param',
'',
'🔧',
10,
true,
true,
1,
now(),
now()
),
-- IAM/api/v1/iam/*
(
'31000000-0000-4000-8000-000000000020',
'',
'权限管理',
1,
'iam:module',
'',
'',
'🛡',
50,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000021',
'31000000-0000-4000-8000-000000000020',
'租户管理',
2,
'iam:tenant:list',
'/dashboard/iam/tenant',
'',
'🏢',
10,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000022',
'31000000-0000-4000-8000-000000000020',
'部门管理',
2,
'iam:dept:tree',
'/dashboard/iam/dept',
'',
'🌳',
20,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000023',
'31000000-0000-4000-8000-000000000020',
'角色管理',
2,
'iam:role:list',
'/dashboard/iam/role',
'',
'👥',
30,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000024',
'31000000-0000-4000-8000-000000000020',
'用户管理',
2,
'iam:user:list',
'/dashboard/iam/user',
'',
'👤',
40,
true,
true,
1,
now(),
now()
),
(
'31000000-0000-4000-8000-000000000025',
'31000000-0000-4000-8000-000000000020',
'资源(菜单)',
2,
'iam:menu:tree',
'/dashboard/iam/resource',
'',
'📋',
50,
true,
true,
1,
now(),
now()
)
ON CONFLICT (id) DO NOTHING;
-- 将上述菜单授权给平台「超级管理员」角色(与 004 中 role id 一致)
INSERT INTO iam_role_menu (id, role_id, menu_id, created_at)
SELECT gen_random_uuid()::text,
'20000000-0000-4000-8000-000000000002',
m.id,
now()
FROM iam_menu m
WHERE m.id IN (
'31000000-0000-4000-8000-000000000001',
'31000000-0000-4000-8000-000000000003',
'31000000-0000-4000-8000-000000000010',
'31000000-0000-4000-8000-000000000011',
'31000000-0000-4000-8000-000000000020',
'31000000-0000-4000-8000-000000000021',
'31000000-0000-4000-8000-000000000022',
'31000000-0000-4000-8000-000000000023',
'31000000-0000-4000-8000-000000000024',
'31000000-0000-4000-8000-000000000025'
)
ON CONFLICT (role_id, menu_id) DO NOTHING;
-- 若曾执行过含「概览」菜单的旧版脚本,可手工清理(避免侧栏与前端固定入口重复):
-- DELETE FROM iam_role_menu WHERE menu_id = '31000000-0000-4000-8000-000000000002';
-- DELETE FROM iam_menu WHERE id = '31000000-0000-4000-8000-000000000002';
COMMIT;