|
| 1 | +-- AdCP decisioning task registry — durable HITL task state. |
| 2 | +-- |
| 3 | +-- Run this once per deployment. Tracked by PostgresTaskRegistry; |
| 4 | +-- see src/adcp/decisioning/pg/task_registry.py for the query shapes |
| 5 | +-- the Python code executes. |
| 6 | +-- |
| 7 | +-- COLLATE "C" on identifier columns avoids locale-dependent case |
| 8 | +-- folding — on some locales "Task-A" and "task-a" compare equal, |
| 9 | +-- which could collapse distinct task_ids or account_ids. "C" is the |
| 10 | +-- byte-for-byte comparison we actually want. |
| 11 | +-- |
| 12 | +-- Alternatively, call PostgresTaskRegistry.create_schema() from |
| 13 | +-- application code — it runs the equivalent DDL idempotently on boot. |
| 14 | + |
| 15 | +CREATE TABLE IF NOT EXISTS decisioning_tasks ( |
| 16 | + task_id TEXT COLLATE "C" NOT NULL PRIMARY KEY, |
| 17 | + account_id TEXT COLLATE "C" NOT NULL, |
| 18 | + state TEXT NOT NULL DEFAULT 'submitted', |
| 19 | + task_type TEXT NOT NULL, |
| 20 | + progress JSONB, |
| 21 | + result JSONB, |
| 22 | + error JSONB, |
| 23 | + -- Unix epoch seconds (float), matches TaskRecord.created_at/updated_at |
| 24 | + -- so Python round-trips the value without lossy TIMESTAMPTZ conversion. |
| 25 | + created_at DOUBLE PRECISION NOT NULL, |
| 26 | + updated_at DOUBLE PRECISION NOT NULL |
| 27 | +); |
| 28 | + |
| 29 | +-- Supports the cross-tenant get() query: WHERE task_id = $1 AND account_id = $2. |
| 30 | +-- Without this index, every tasks/get is a full-table scan on account_id. |
| 31 | +CREATE INDEX IF NOT EXISTS decisioning_tasks_account_idx |
| 32 | + ON decisioning_tasks (account_id); |
0 commit comments