-- Rollback T23 auto-repair executor read-only MCP Gateway grant.

SELECT set_config('app.project_id', 'awoooi', FALSE);

UPDATE awooop_mcp_grants
SET is_revoked = TRUE,
    revoked_at = NOW(),
    revoked_by = 'rollback:t23_auto_repair_executor_read_gateway'
WHERE project_id = 'awoooi'
  AND agent_id = 'auto_repair_executor'
  AND granted_by = 'migration:t23_auto_repair_executor_read_gateway';

DELETE FROM awooop_active_revisions
WHERE project_id = 'awoooi'
  AND contract_family = 'agent'
  AND contract_id = 'auto_repair_executor';

UPDATE awooop_contract_revisions
SET lifecycle_status = 'retired'
WHERE project_id = 'awoooi'
  AND contract_family = 'agent'
  AND contract_id = 'auto_repair_executor'
  AND publisher_id = 'migration:t23_auto_repair_executor_read_gateway'
  AND lifecycle_status = 'active';
