-- +goose Up

-- 新增“撤销用户实名”权限：用于实名姓名与收款账户不一致导致收款码登记失败时，
-- 由后台撤销用户实名，让用户可重新发起实名认证。
INSERT INTO permissions (code, name, resource, action) VALUES
('user:revoke_realname', '撤销用户实名', 'user', 'revoke_realname')
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  resource = VALUES(resource),
  action = VALUES(action);

-- super_admin 拥有全部权限，补授新权限。
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r, permissions p
WHERE r.code = 'super_admin' AND p.code = 'user:revoke_realname';

-- ops（运营）负责用户管理，授予撤销实名权限。
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 = 'user:revoke_realname';

-- +goose Down

DELETE rp FROM role_permissions rp
JOIN permissions p ON p.id = rp.permission_id
WHERE p.code = 'user:revoke_realname';

DELETE FROM permissions WHERE code = 'user:revoke_realname';
