Skip to content

Commit

Permalink
chore: adding new migration for notification and updating ERD
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Oct 25, 2023
1 parent 657a43f commit 42307a3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
25 changes: 25 additions & 0 deletions migrations/20231025145134_add_notification.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TYPE notification_states
AS ENUM ('queued', 'processing', 'published', 'not-subscribed', 'wrong-scope', 'rate-limited');

CREATE TABLE notification (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
type VARCHAR(255) NOT NULL,
title VARCHAR(255) NOT NULL,
body VARCHAR(255) NOT NULL,
icon VARCHAR(255) NOT NULL,
url VARCHAR(255) NOT NULL
);

CREATE TABLE notification_status (
PRIMARY KEY (notification_id, subscriber_id),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
state notification_states NOT NULL,
notification_id UUID NOT NULL REFERENCES notification (id) ON DELETE CASCADE,
subscriber_id UUID NOT NULL REFERENCES subscriber (id) ON DELETE CASCADE
);
CREATE INDEX notification_delivery_subscriber_id ON notification_status (subscriber_id);
CREATE INDEX notification_delivery_notification_id ON notification_status (notification_id);
CREATE INDEX notification_delivery_state ON notification_status (state);
CREATE INDEX notification_delivery_created_and_updated ON notification_status (created_at, updated_at);
26 changes: 19 additions & 7 deletions migrations/ERD.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,35 @@ erDiagram
}
subscription_watcher }o--o| project : "watching"
notification_states {
enum queued
enum processing
enum published
enum not-subscribed
enum wrong-scope
enum rate-limited
}
notification_states }|..|{ notification_status : "uses"
notification {
uuid id PK
uuid subscriber FK
timestamp created_at
string type
string title
string body
string icon
string url
}
notification }o--|| subscriber : "sent to"
notification_event {
uuid id PK
uuid message FK
enum name "queued, sent, delivered, read, deleted"
timestamp time
notification_status {
timestamp created_at
timestamp updated_at
enum state notification_states
uuid notification_id FK
uuid subscriber_id FK
}
notification_event }o--|| notification : "for"
notification_status }o--|| notification : "for"
webhook {
uuid id PK
Expand Down

0 comments on commit 42307a3

Please sign in to comment.