-- 添加新菜单：个人信息 和 我的天体
-- 这两个菜单对普通用户也开放

-- 1. 添加"个人信息"菜单（普通用户可访问）
INSERT INTO menus (name, title, path, icon, parent_id, sort_order, is_active, roles)
VALUES (
    'user-profile',
    '个人信息',
    '/admin/user-profile',
    'users',
    NULL,
    15,
    true,
    ARRAY['user', 'admin']::varchar[]
)
ON CONFLICT (name) DO UPDATE SET
    title = EXCLUDED.title,
    path = EXCLUDED.path,
    icon = EXCLUDED.icon,
    parent_id = EXCLUDED.parent_id,
    sort_order = EXCLUDED.sort_order,
    roles = EXCLUDED.roles;

-- 2. 添加"我的天体"菜单（普通用户可访问）
INSERT INTO menus (name, title, path, icon, parent_id, sort_order, is_active, roles)
VALUES (
    'my-celestial-bodies',
    '我的天体',
    '/admin/my-celestial-bodies',
    'planet',
    NULL,
    16,
    true,
    ARRAY['user', 'admin']::varchar[]
)
ON CONFLICT (name) DO UPDATE SET
    title = EXCLUDED.title,
    path = EXCLUDED.path,
    icon = EXCLUDED.icon,
    parent_id = EXCLUDED.parent_id,
    sort_order = EXCLUDED.sort_order,
    roles = EXCLUDED.roles;

-- 3. 添加"修改密码"菜单（普通用户和管理员都可访问）
-- 注意：修改密码功能通过用户下拉菜单访问，不需要在侧边栏显示
-- 但是我们仍然需要在数据库中记录这个菜单以便权限管理
INSERT INTO menus (name, title, path, icon, parent_id, sort_order, is_active, roles)
VALUES (
    'change-password',
    '修改密码',
    '/admin/change-password',
    'settings',
    NULL,
    17,
    true,
    ARRAY['user', 'admin']::varchar[]
)
ON CONFLICT (name) DO UPDATE SET
    title = EXCLUDED.title,
    path = EXCLUDED.path,
    icon = EXCLUDED.icon,
    parent_id = EXCLUDED.parent_id,
    sort_order = EXCLUDED.sort_order,
    roles = EXCLUDED.roles;

-- 4. 调整其他菜单的排序（可选）
-- 如果需要调整现有菜单的顺序，可以更新 sort_order
UPDATE menus SET sort_order = 18 WHERE name = 'settings' AND sort_order < 18;

-- 5. 查看更新后的菜单列表
SELECT id, name, title, path, icon, parent_id, sort_order, is_active, roles
FROM menus
WHERE is_active = true
ORDER BY sort_order;
