Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 3 new database tables for Call-Mod-to-Thread feature #140

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions db/init/090_subscriptions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)