Skip to content

Commit

Permalink
nice clean: create 3 database tables
Browse files Browse the repository at this point in the history
  • Loading branch information
akrobi authored and essential-randomness committed Jul 3, 2023
1 parent 920d077 commit 0eb82b4
Showing 1 changed file with 31 additions and 0 deletions.
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
)

0 comments on commit 0eb82b4

Please sign in to comment.