diff --git a/internal/infrastructure/db/migrations/000395_campaign_send_tracking.down.sql b/internal/infrastructure/db/migrations/000395_campaign_send_tracking.down.sql index 87d3c4f1e..eab47e43b 100644 --- a/internal/infrastructure/db/migrations/000395_campaign_send_tracking.down.sql +++ b/internal/infrastructure/db/migrations/000395_campaign_send_tracking.down.sql @@ -1,3 +1,17 @@ +-- Refuse rather than discard which sends carried tracking; the rates read it and nothing can rebuild it. +DO $$ +DECLARE + recorded boolean; +BEGIN + IF EXISTS (SELECT 1 FROM information_schema.columns + WHERE table_schema = current_schema() AND table_name = 'campaign_contact_progress' AND column_name = 'open_tracked') THEN + EXECUTE 'SELECT EXISTS (SELECT 1 FROM campaign_contact_progress WHERE open_tracked IS NOT NULL OR click_tracked IS NOT NULL)' INTO recorded; + IF recorded THEN + RAISE EXCEPTION 'campaign sends recorded their tracking after 000395; roll forward instead of downgrading past it'; + END IF; + END IF; +END $$; + ALTER TABLE campaign_contact_progress DROP COLUMN IF EXISTS open_tracked, DROP COLUMN IF EXISTS click_tracked;