-- 添加公告管理权限

INSERT INTO permissions (code, name, resource, action) VALUES
('announcement:view',    '查看公告',    'announcement',  'view'),
('announcement:manage',  '管理公告',    'announcement',  'manage')
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  resource = VALUES(resource),
  action = VALUES(action);

-- 为超级管理员添加公告权限
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r CROSS JOIN permissions p
WHERE r.code = 'super_admin' AND p.code IN ('announcement:view', 'announcement:manage');

-- 为运营角色添加公告权限
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r, permissions p
WHERE r.code = 'ops' AND p.code IN ('announcement:view', 'announcement:manage');
