20260723_180_rule_reconciliation.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Add bounded reconciliation claims for Runner and rule evidence."""
  2. from alembic import op
  3. revision = "20260723_180"
  4. down_revision = "20260723_170"
  5. branch_labels = None
  6. depends_on = None
  7. def upgrade() -> None:
  8. op.execute(
  9. """
  10. ALTER TABLE public.runner_task_executions
  11. ADD COLUMN lease_expires_at TIMESTAMPTZ NOT NULL
  12. DEFAULT CURRENT_TIMESTAMP;
  13. ALTER TABLE public.rule_violation_samples
  14. DROP CONSTRAINT
  15. rule_violation_samples_handoff_status_check,
  16. ADD CONSTRAINT
  17. rule_violation_samples_handoff_status_check
  18. CHECK (handoff_status IN (
  19. 'legacy','pending','ready','failed',
  20. 'unknown','expired'
  21. )),
  22. ADD COLUMN cleanup_claim UUID,
  23. ADD COLUMN schema_fields JSONB;
  24. CREATE INDEX idx_rule_violation_sample_cleanup_claim
  25. ON public.rule_violation_samples(
  26. cleanup_claim, expires_at, id
  27. );
  28. ALTER TABLE public.rule_sql_staging_receipts
  29. ADD COLUMN cleanup_claim UUID;
  30. CREATE INDEX idx_rule_sql_receipt_cleanup_claim
  31. ON public.rule_sql_staging_receipts(
  32. cleanup_claim, expires_at, id
  33. );
  34. """
  35. )
  36. def downgrade() -> None:
  37. raise RuntimeError(
  38. "rule reconciliation claims are forward-only"
  39. )