From d4b57059721e6704e7d4de483340808477758284 Mon Sep 17 00:00:00 2001 From: Caleb McQuaid Date: Tue, 30 Jun 2026 00:24:32 -0400 Subject: [PATCH] fix: remove table constraint for NCMEC non-media submissions --- ...03.50.47.allow_text_only_ncmec_reports.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 db/src/scripts/api-server-pg/2026.06.30T03.50.47.allow_text_only_ncmec_reports.sql diff --git a/db/src/scripts/api-server-pg/2026.06.30T03.50.47.allow_text_only_ncmec_reports.sql b/db/src/scripts/api-server-pg/2026.06.30T03.50.47.allow_text_only_ncmec_reports.sql new file mode 100644 index 000000000..7f2414677 --- /dev/null +++ b/db/src/scripts/api-server-pg/2026.06.30T03.50.47.allow_text_only_ncmec_reports.sql @@ -0,0 +1,30 @@ +-- The existing `reported_media_check_non_empty` CHECK on ncmec_reporting.ncmec_reports +-- requires >= 1 media item, which blocks storing legitimate text-only reports +-- even after the application-side media gates were removed (#661). +-- +-- We want to replace it with a constraint that matches the new logic. A +-- report must carry media OR messages (but there must be one). `array_length` of an +-- empty/NULL array is NULL, so coalesce to 0 before comparing. The column stays +-- `jsonb[] NOT NULL`, so rows still cannot be NULL. +-- +-- Safe for existing data: every current row satisfied the old "media non-empty" +-- constraint, so it satisfies "media OR messages non-empty". +-- +-- Rollback caveat: reverting to the media-only constraint will FAIL once any +-- text-only (empty reported_media) row exists. Reverting is only clean +-- before such rows are written; afterward it requires removing/backfilling +-- those rows, and deleting NCMEC report records has compliance implications. +-- Treat this as effectively forward-only. + +BEGIN; + +ALTER TABLE ncmec_reporting.ncmec_reports + DROP CONSTRAINT IF EXISTS reported_media_check_non_empty; + +ALTER TABLE ncmec_reporting.ncmec_reports + ADD CONSTRAINT reported_media_or_messages_non_empty CHECK ( + coalesce(array_length(reported_media, 1), 0) > 0 + OR coalesce(array_length(reported_messages, 1), 0) > 0 + ); + +COMMIT;