20260723_210_dataflow_draft_reservations.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Add single-use actor-bound DataFlow draft reservations."""
  2. from alembic import op
  3. revision = "20260723_210"
  4. down_revision = "20260723_200"
  5. branch_labels = None
  6. depends_on = None
  7. def upgrade() -> None:
  8. op.execute(
  9. """
  10. CREATE TABLE public.dataflow_draft_reservations (
  11. id UUID PRIMARY KEY,
  12. dataflow_uid UUID NOT NULL UNIQUE,
  13. actor_uid UUID NOT NULL
  14. REFERENCES public.users(id) ON DELETE RESTRICT,
  15. nonce_hash CHAR(64) NOT NULL UNIQUE,
  16. expires_at TIMESTAMPTZ NOT NULL,
  17. consumed_at TIMESTAMPTZ,
  18. created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
  19. CHECK (expires_at > created_at)
  20. );
  21. CREATE INDEX idx_dataflow_draft_reservation_actor
  22. ON public.dataflow_draft_reservations(
  23. actor_uid, expires_at, consumed_at
  24. );
  25. """
  26. )
  27. def downgrade() -> None:
  28. raise RuntimeError(
  29. "DataFlow draft reservations are forward-only and cannot downgrade"
  30. )