Add unique constraint on user_id and event_types

This commit is contained in:
Hongbo Wu 2022-05-25 21:12:19 +08:00
parent aaab02c9d8
commit a655275754
2 changed files with 4 additions and 1 deletions

View file

@ -1614,6 +1614,7 @@ const schema = gql`
enum CreateWebhookErrorCode {
UNAUTHORIZED
BAD_REQUEST
ALREADY_EXISTS
}
# Mutations

View file

@ -6,13 +6,15 @@ BEGIN;
CREATE TABLE omnivore.webhooks (
id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
user_id uuid NOT NULL REFERENCES omnivore.user ON DELETE CASCADE,
url text NOT NULL,
method text NOT NULL DEFAULT 'POST',
content_type text NOT NULL DEFAULT 'application/json',
active boolean NOT NULL DEFAULT true,
event_types text[] NOT NULL,
created_at timestamptz NOT NULL DEFAULT current_timestamp,
updated_at timestamptz NOT NULL DEFAULT current_timestamp
updated_at timestamptz NOT NULL DEFAULT current_timestamp,
UNIQUE (user_id, event_types)
);
CREATE TRIGGER update_webhook_modtime BEFORE UPDATE ON omnivore.webhooks