lemmy/migrations/2024-11-26-115042_add_combined_tables/up.sql

44 lines
1.3 KiB
MySQL
Raw Normal View History

-- Creates combined tables for the following:
--
-- Reports: (comment, post, and private_message)
-- Inbox: (Comment replies, post replies, comment mentions, post mentions, private messages)
-- Modlog: (lots of types)
-- Search: (community, post, comment, user, url)
-- TODO not sure about these two:
-- Home: (comment, post)
-- Community: (comment, post)
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-11-26 14:27:05 +00:00
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,
2024-11-26 21:53:01 +00:00
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)
2024-11-26 14:27:05 +00:00
);
2024-11-26 21:53:01 +00:00
CREATE INDEX idx_report_combined_published ON report_combined (published DESC);
2024-11-26 14:27:05 +00:00
-- Updating the history
INSERT INTO report_combined (published, post_report_id)
SELECT
published,
id
FROM
post_report;
INSERT INTO report_combined (published, comment_report_id)
SELECT
published,
id
FROM
comment_report;
INSERT INTO report_combined (published, private_message_report_id)
SELECT
published,
id
FROM
private_message_report;
2024-11-26 14:27:05 +00:00
-- TODO do triggers in replaceable schema