SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

SET @now_ms = CAST(UNIX_TIMESTAMP(UTC_TIMESTAMP(3)) * 1000 AS UNSIGNED);

-- 线上生产环境关闭 bootstrap 和 AutoMigrate，新按钮权限必须通过 migration 落库，
-- 否则前端即使已经上线，也会因为登录权限列表缺少该 code 而隐藏“工资兑换比例”按钮。
INSERT INTO admin_permissions (name, code, kind, description, created_at_ms, updated_at_ms) VALUES
  ('币商工资兑换比例', 'coin-seller:exchange-rate', 'button', '', @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  kind = VALUES(kind),
  description = VALUES(description),
  updated_at_ms = @now_ms;

-- 平台管理员应拥有全部后台能力；运维管理员也需要维护币商工资转金币比例。
-- INSERT IGNORE 保持幂等，重复执行不会产生重复绑定。
INSERT IGNORE INTO admin_role_permissions (role_id, permission_id)
SELECT admin_role.id, admin_permission.id
FROM admin_roles admin_role
JOIN admin_permissions admin_permission
WHERE admin_role.code IN ('platform-admin', 'ops-admin')
  AND admin_permission.code = 'coin-seller:exchange-rate';
