2024-12-04 17:48:41 +00:00
|
|
|
-- Creates combined tables for
|
2024-11-27 21:02:11 +00:00
|
|
|
-- Reports: (comment, post, and private_message)
|
2024-11-26 14:27:05 +00:00
|
|
|
CREATE TABLE report_combined (
|
|
|
|
id serial PRIMARY KEY,
|
2024-11-26 21:53:01 +00:00
|
|
|
published timestamptz NOT NULL,
|
2024-12-03 17:18:13 +00:00
|
|
|
post_report_id int UNIQUE REFERENCES post_report ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
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,
|
2024-12-02 21:23:50 +00:00
|
|
|
-- Make sure only one of the columns is not null
|
2024-12-08 13:44:37 +00:00
|
|
|
CHECK (num_nonnulls (post_report_id, comment_report_id, private_message_report_id) = 1)
|
2024-11-26 14:27:05 +00:00
|
|
|
);
|
|
|
|
|
2024-12-02 17:56:14 +00:00
|
|
|
CREATE INDEX idx_report_combined_published ON report_combined (published DESC, id DESC);
|
|
|
|
|
|
|
|
CREATE INDEX idx_report_combined_published_asc ON report_combined (reverse_timestamp_sort (published) DESC, id DESC);
|
2024-11-26 14:27:05 +00:00
|
|
|
|
2024-11-27 21:02:11 +00:00
|
|
|
-- Updating the history
|
2024-12-08 13:45:49 +00:00
|
|
|
INSERT INTO report_combined (published, post_report_id, comment_report_id, private_message_report_id)
|
2024-11-27 21:02:11 +00:00
|
|
|
SELECT
|
|
|
|
published,
|
2024-12-08 13:45:49 +00:00
|
|
|
id,
|
2024-12-08 13:56:12 +00:00
|
|
|
NULL::int,
|
|
|
|
NULL::int
|
2024-11-27 21:02:11 +00:00
|
|
|
FROM
|
2024-12-08 13:45:49 +00:00
|
|
|
post_report
|
|
|
|
UNION ALL
|
2024-11-27 21:02:11 +00:00
|
|
|
SELECT
|
|
|
|
published,
|
2024-12-08 13:56:12 +00:00
|
|
|
NULL::int,
|
2024-12-08 13:45:49 +00:00
|
|
|
id,
|
2024-12-08 13:56:12 +00:00
|
|
|
NULL::int
|
2024-11-27 21:02:11 +00:00
|
|
|
FROM
|
2024-12-08 13:45:49 +00:00
|
|
|
comment_report
|
|
|
|
UNION ALL
|
2024-11-27 21:02:11 +00:00
|
|
|
SELECT
|
|
|
|
published,
|
2024-12-08 13:56:12 +00:00
|
|
|
NULL::int,
|
|
|
|
NULL::int,
|
2024-11-27 21:02:11 +00:00
|
|
|
id
|
|
|
|
FROM
|
|
|
|
private_message_report;
|
|
|
|
|