-- +goose Up

-- 新增“调整用户余额”权限：线下打款核销、补偿加款等人工余额管理。
INSERT INTO permissions (code, name, resource, action) VALUES
('user:wallet_adjust', '调整用户余额', 'user', 'wallet_adjust')
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:wallet_adjust';

-- 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:wallet_adjust';

-- +goose Down

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

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