From 612c2e916ff84211a51bb0b69bc6df97a63a6e8f Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 2 Dec 2024 16:23:50 -0500 Subject: [PATCH] Fixing column XOR check. --- migrations/2024-12-02-181601_add_combined_tables/up.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations/2024-12-02-181601_add_combined_tables/up.sql b/migrations/2024-12-02-181601_add_combined_tables/up.sql index ef7900ddd..236d7ab14 100644 --- a/migrations/2024-12-02-181601_add_combined_tables/up.sql +++ b/migrations/2024-12-02-181601_add_combined_tables/up.sql @@ -14,7 +14,8 @@ CREATE TABLE report_combined ( post_report_id int REFERENCES post_report ON UPDATE CASCADE ON DELETE CASCADE, comment_report_id int REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE, private_message_report_id int REFERENCES private_message_report ON UPDATE CASCADE ON DELETE CASCADE, - UNIQUE (post_report_id, comment_report_id, private_message_report_id) + -- Make sure only one of the columns is not null + CHECK ((post_report_id IS NOT NULL)::integer + (comment_report_id IS NOT NULL)::integer + (private_message_report_id IS NOT NULL)::integer = 1) ); CREATE INDEX idx_report_combined_published ON report_combined (published DESC, id DESC);