-- 收款地址是按 APP 隔离的财务敏感配置；独立写权限避免仅有订单查看权限的账号修改校验口径。
-- 迁移只通过角色 code、权限 code 唯一索引写少量元数据，不扫描订单或配置业务表。
SET @now_ms = CAST(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000 AS UNSIGNED);

INSERT INTO admin_permissions (name, code, kind, description, created_at_ms, updated_at_ms)
VALUES ('USDT 收款地址编辑', 'finance-order:usdt-address:update', 'button', '允许按 APP 新增或修改 USDT 收款地址', @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  kind = VALUES(kind),
  description = VALUES(description),
  updated_at_ms = @now_ms;

-- 平台管理员、运营负责人和运营专员原本都能创建并校验币商充值订单；地址维护沿用同一岗位边界。
INSERT IGNORE INTO admin_role_permissions (role_id, permission_id)
SELECT role.id, permission.id
FROM admin_roles role
JOIN admin_permissions permission
WHERE role.code IN ('platform-admin', 'ops-admin', 'operations-specialist')
  AND permission.code = 'finance-order:usdt-address:update';
