-- 平台域补充文件下载权限（用于Logo等资源预览）

INSERT INTO platform_permission (permission_code, permission_name, module)
VALUES ('file.download', '下载文件', 'file')
ON DUPLICATE KEY UPDATE
    permission_name = VALUES(permission_name),
    module = VALUES(module);

INSERT INTO platform_role_permission (role_id, permission_id)
SELECT r.id, p.id
FROM platform_role r
JOIN platform_permission p ON p.permission_code = 'file.download'
WHERE r.role_code = 'PLATFORM_SUPER_ADMIN'
  AND NOT EXISTS (
      SELECT 1
      FROM platform_role_permission rp
      WHERE rp.role_id = r.id
        AND rp.permission_id = p.id
  );
