-- PR-4 Email Ingest — partial unique on (source_external_id) for email source
-- inbox_ingest 의 dedup 진실원장. 같은 메일 재 ingest 시 ON CONFLICT DO NOTHING.
-- mailplus_archive 의 INBOX root archive row 는 source_external_id=NULL 이라 자동 제외.

CREATE UNIQUE INDEX IF NOT EXISTS uq_documents_email_source_external_id
    ON documents (source_external_id)
    WHERE source_channel = 'email' AND source_external_id IS NOT NULL;
