new-site/api/migrations/039_crtc_defer_and_idempotency.sql
justin f8cd37ac8c Initial commit — Performance West telecom compliance platform
Includes: API (Express/TypeScript), Astro site, Python workers,
document generators, FCC compliance tools, Canada CRTC formation,
Ansible infrastructure, and deployment scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 06:54:22 -05:00

20 lines
949 B
SQL

-- 039: Add defer_until + idempotency markers to canada_crtc_orders
--
-- defer_until: timestamp until which the worker should not run this order's pipeline.
-- Used by the standard-vs-expedited delay system.
--
-- binder_emailed_at / binder_compiled_at / binder_uploaded_at: idempotency markers
-- for Steps 7-9 so the pipeline can resume after a defer without re-doing work
-- (preventing duplicate client emails).
ALTER TABLE canada_crtc_orders
ADD COLUMN IF NOT EXISTS defer_until TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS automation_note TEXT,
ADD COLUMN IF NOT EXISTS binder_compiled_at TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS binder_uploaded_at TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS binder_emailed_at TIMESTAMPTZ;
-- Index for the deferred order poller
CREATE INDEX IF NOT EXISTS idx_crtc_orders_deferred
ON canada_crtc_orders (defer_until)
WHERE automation_status = 'Deferred' AND defer_until IS NOT NULL;