Merged in bugfix/delete-client-cascade (pull request #220)

fix cascading delete issue

* test passing
This commit is contained in:
Jay Brown
2026-04-08 10:54:32 +00:00
parent b71a28d3c0
commit ad7b21f3a2
8 changed files with 229 additions and 0 deletions
@@ -0,0 +1,15 @@
-- Revert to original FK constraints (NO ACTION).
ALTER TABLE batch_document_outcomes
DROP CONSTRAINT fk_batch_doc_outcomes_document_id;
ALTER TABLE batch_document_outcomes
DROP CONSTRAINT fk_batch_doc_outcomes_batch_id;
ALTER TABLE batch_document_outcomes
ADD CONSTRAINT batch_document_outcomes_document_id_fkey
FOREIGN KEY (document_id) REFERENCES documents(id);
ALTER TABLE batch_document_outcomes
ADD CONSTRAINT batch_document_outcomes_batch_id_fkey
FOREIGN KEY (batch_id) REFERENCES batch_uploads(id);
@@ -0,0 +1,17 @@
-- Fix batch_document_outcomes FK constraints to support cascading deletes.
-- document_id: SET NULL preserves batch outcome history when a document is hard-deleted.
-- batch_id: CASCADE removes outcome rows when their owning batch_upload is deleted.
ALTER TABLE batch_document_outcomes
DROP CONSTRAINT batch_document_outcomes_document_id_fkey;
ALTER TABLE batch_document_outcomes
DROP CONSTRAINT batch_document_outcomes_batch_id_fkey;
ALTER TABLE batch_document_outcomes
ADD CONSTRAINT fk_batch_doc_outcomes_document_id
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE SET NULL;
ALTER TABLE batch_document_outcomes
ADD CONSTRAINT fk_batch_doc_outcomes_batch_id
FOREIGN KEY (batch_id) REFERENCES batch_uploads(id) ON DELETE CASCADE;