cosmo/backend/scripts/add_star_systems_menu.sql

55 lines
1.4 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 添加恒星系统管理菜单项
-- 将其放在天体数据管理之前sort_order=0
-- 首先调整天体数据管理的sort_order从1改为2
UPDATE menus SET sort_order = 2 WHERE id = 3 AND name = 'celestial_bodies';
-- 添加恒星系统管理菜单sort_order=1在天体数据管理之前
INSERT INTO menus (
parent_id,
name,
title,
icon,
path,
component,
sort_order,
is_active,
description
) VALUES (
2, -- parent_id: 数据管理
'star_systems',
'恒星系统管理',
'StarOutlined',
'/admin/star-systems',
'StarSystems',
1, -- sort_order: 在天体数据管理(2)之前
true,
'管理太阳系和系外恒星系统'
) ON CONFLICT DO NOTHING;
-- 获取新插入的菜单ID并为管理员角色授权
DO $$
DECLARE
menu_id INT;
admin_role_id INT;
BEGIN
-- 获取刚插入的菜单ID
SELECT id INTO menu_id FROM menus WHERE name = 'star_systems';
-- 获取管理员角色ID通常是1
SELECT id INTO admin_role_id FROM roles WHERE name = 'admin' LIMIT 1;
-- 为管理员角色授权
IF menu_id IS NOT NULL AND admin_role_id IS NOT NULL THEN
INSERT INTO role_menus (role_id, menu_id)
VALUES (admin_role_id, menu_id)
ON CONFLICT DO NOTHING;
END IF;
END $$;
-- 验证结果
SELECT id, name, title, path, parent_id, sort_order
FROM menus
WHERE parent_id = 2
ORDER BY sort_order, id;