new-site/api/migrations/083_fmcsa_campaign_tracking.sql
justin dcd9fb61d0 migration 083: use CREATE INDEX CONCURRENTLY to avoid locking fmcsa_carriers
The original CREATE INDEX (non-concurrent) on a 2M-row table held a SHARE lock
for ~33 minutes, blocking all 25+ DOT checker queries and causing 'Failed to
fetch' for real users. CONCURRENTLY builds the index without a table lock.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 10:42:47 -05:00

10 lines
443 B
SQL

-- Track which fmcsa_carriers records have been added to Listmonk campaign lists,
-- so the daily campaign builder never double-sends to the same carrier.
ALTER TABLE fmcsa_carriers
ADD COLUMN IF NOT EXISTS listmonk_sent_at TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS listmonk_campaign_type TEXT;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_fmcsa_carriers_listmonk_sent
ON fmcsa_carriers (listmonk_sent_at)
WHERE listmonk_sent_at IS NULL;