20260719_70_runner_task_ledger.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """Add the durable single-use Runner task execution ledger."""
  2. from alembic import op
  3. revision = "20260719_70"
  4. down_revision = "20260718_60"
  5. branch_labels = None
  6. depends_on = None
  7. def upgrade() -> None:
  8. op.execute(
  9. """
  10. CREATE TABLE public.runner_task_executions (
  11. token_jti UUID PRIMARY KEY,
  12. task_uid UUID NOT NULL,
  13. dataflow_uid UUID NOT NULL,
  14. workflow_version INTEGER NOT NULL CHECK (workflow_version > 0),
  15. correlation_id UUID NOT NULL,
  16. node_id VARCHAR(100) NOT NULL,
  17. node_type VARCHAR(100) NOT NULL,
  18. data_source_uid UUID,
  19. idempotency_key VARCHAR(500),
  20. status VARCHAR(20) NOT NULL
  21. CHECK (status IN ('running', 'success', 'failed', 'unknown')),
  22. commit_outcome VARCHAR(30) NOT NULL
  23. CHECK (commit_outcome IN (
  24. 'not_applicable', 'not_committed', 'committed', 'unknown'
  25. )),
  26. safe_detail VARCHAR(500),
  27. expires_at TIMESTAMPTZ NOT NULL,
  28. started_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
  29. finished_at TIMESTAMPTZ,
  30. UNIQUE (task_uid)
  31. );
  32. CREATE INDEX idx_runner_task_executions_correlation
  33. ON public.runner_task_executions(correlation_id, started_at DESC);
  34. CREATE INDEX idx_runner_task_executions_datasource
  35. ON public.runner_task_executions(data_source_uid, started_at DESC)
  36. WHERE data_source_uid IS NOT NULL;
  37. CREATE INDEX idx_runner_task_executions_expiry
  38. ON public.runner_task_executions(expires_at);
  39. """
  40. )
  41. def downgrade() -> None:
  42. op.execute(
  43. "DROP TABLE IF EXISTS public.runner_task_executions;"
  44. )