-- 内容黑名单复用 app-user:view/status 权限，仅新增用户管理子菜单。
-- admin_menus.code 有唯一索引，以下调整都是点查/点更；不扫描或锁定 App 用户业务表。
SET @now_ms := UNIX_TIMESTAMP(UTC_TIMESTAMP(3)) * 1000;

UPDATE admin_menus
SET sort = CASE code
  WHEN 'app-user-login-logs' THEN 63
  WHEN 'app-user-level-config' THEN 64
  WHEN 'app-user-pretty-ids' THEN 65
  WHEN 'app-user-risk-config' THEN 66
  WHEN 'app-user-region-blocks' THEN 67
  ELSE sort
END,
updated_at_ms = @now_ms
WHERE code IN (
  'app-user-login-logs',
  'app-user-level-config',
  'app-user-pretty-ids',
  'app-user-risk-config',
  'app-user-region-blocks'
);

INSERT INTO admin_menus (
  parent_id, title, code, path, icon, permission_code, sort, visible, created_at_ms, updated_at_ms
)
SELECT parent.id,
       '黑名单屏蔽用户',
       'app-user-content-blacklist',
       '/app/users/content-blacklist',
       'visibility_off',
       'app-user:view',
       62,
       TRUE,
       @now_ms,
       @now_ms
FROM admin_menus parent
WHERE parent.code = 'app-users'
ON DUPLICATE KEY UPDATE
  parent_id = VALUES(parent_id),
  title = VALUES(title),
  path = VALUES(path),
  icon = VALUES(icon),
  permission_code = VALUES(permission_code),
  sort = VALUES(sort),
  visible = VALUES(visible),
  updated_at_ms = VALUES(updated_at_ms);
