20260724_230_dataflow_create_intent.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Bind recoverable DataFlow creates to a canonical server-owned intent."""
  2. from alembic import op
  3. revision = "20260724_230"
  4. down_revision = "20260724_220"
  5. branch_labels = None
  6. depends_on = None
  7. def upgrade() -> None:
  8. op.execute(
  9. """
  10. ALTER TABLE public.dataflow_draft_reservations
  11. ADD COLUMN create_request JSONB,
  12. ADD COLUMN create_intent JSONB,
  13. ADD COLUMN request_digest CHAR(64);
  14. ALTER TABLE public.dataflow_draft_reservations
  15. ADD CONSTRAINT ck_dataflow_create_intent_complete
  16. CHECK (
  17. (
  18. create_request IS NULL
  19. AND create_intent IS NULL
  20. AND request_digest IS NULL
  21. )
  22. OR (
  23. create_request IS NOT NULL
  24. AND create_intent IS NOT NULL
  25. AND request_digest ~ '^[0-9a-f]{64}$'
  26. )
  27. );
  28. CREATE INDEX idx_dataflow_create_reconciliation
  29. ON public.dataflow_draft_reservations(
  30. state, lease_expires_at, updated_at
  31. )
  32. WHERE request_digest IS NOT NULL
  33. AND create_intent IS NOT NULL;
  34. """
  35. )
  36. def downgrade() -> None:
  37. raise RuntimeError(
  38. "DataFlow create intents are forward-only and cannot downgrade"
  39. )