diff --git a/db/init/090_subscriptions.sql b/db/init/090_subscriptions.sql index 9e5e1cfd..f8cbe706 100644 --- a/db/init/090_subscriptions.sql +++ b/db/init/090_subscriptions.sql @@ -28,6 +28,13 @@ CREATE TABLE IF NOT EXISTS subscription_webhooks ); CREATE UNIQUE INDEX subscription_webhook on subscription_webhooks(subscription_id, webhook_id); +CREATE TABLE IF NOT EXISTS realm_report_webhooks +( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY NOT NULL, + realm_id BIGINT REFERENCES realms(id) ON DELETE RESTRICT NOT NULL, + webhook_id BIGINT REFERENCES webhooks(id) ON DELETE RESTRICT NOT NULL +); + CREATE TABLE IF NOT EXISTS board_category_subscriptions ( subscription_id BIGINT REFERENCES subscriptions(id) ON DELETE RESTRICT NOT NULL, @@ -43,3 +50,27 @@ CREATE TABLE IF NOT EXISTS thread_category_subscriptions subscription_id BIGINT REFERENCES subscriptions(id) ON DELETE RESTRICT NOT NULL ); CREATE UNIQUE INDEX thread_category_subscriptions_entry on thread_category_subscriptions(thread_id, category_id, subscription_id); + +CREATE TABLE IF NOT EXISTS user_reports +( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY NOT NULL, + reporter_id BIGINT REFERENCES users(id) ON DELETE RESTRICT NOT NULL, + reported_at timestamp NOT NULL DEFAULT now(), + text TEXT NOT NULL, + reported_thread_id BIGINT REFERENCES threads(id) ON DELETE RESTRICT, + reported_post_id BIGINT REFERENCES posts(id) ON DELETE RESTRICT, + reported_comment_id BIGINT REFERENCES comments(id) ON DELETE RESTRICT, + CONSTRAINT at_most_one + CHECK ( + (reported_thread_id IS NOT NULL)::INT + + (reported_post_id IS NOT NULL)::INT + + (reported_comment_id IS NOT NULL)::INT <= 1 + ) +); + +CREATE TABLE IF NOT EXISTS user_report_deliveries +( + report_id BIGINT REFERENCES user_reports(id) ON DELETE RESTRICT NOT NULL, + webhook_id BIGINT REFERENCES realm_report_webhooks(id) ON DELETE RESTRICT NOT NULL, + sent_at timestamp +) \ No newline at end of file