Update migrations/2024-12-02-181601_add_report_combined_table/up.sql

Co-authored-by: dullbananas <dull.bananas0@gmail.com>
This commit is contained in:
Dessalines 2024-12-08 08:44:37 -05:00 committed by GitHub
parent 22d869730d
commit fa31fc37d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,7 +7,7 @@ CREATE TABLE report_combined (
comment_report_id int UNIQUE REFERENCES comment_report ON UPDATE CASCADE ON DELETE CASCADE,
private_message_report_id int UNIQUE REFERENCES private_message_report ON UPDATE CASCADE ON DELETE CASCADE,
-- 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)
CHECK (num_nonnulls (post_report_id, comment_report_id, private_message_report_id) = 1)
);
CREATE INDEX idx_report_combined_published ON report_combined (published DESC, id DESC);