-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
39 lines (35 loc) · 995 Bytes
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
email TEXT UNIQUE,
username TEXT UNIQUE,
hashed_password TEXT,
max_token_age TIMESTAMP,
created_at TIMESTAMP
);
CREATE TABLE IF NOT EXISTS conversations (
id TEXT PRIMARY KEY,
type INT,
name TEXT,
is_draft BOOLEAN,
created_at TIMESTAMP
);
CREATE TABLE IF NOT EXISTS conversation_members (
conversation_id TEXT REFERENCES conversations ON DELETE CASCADE,
user_id TEXT REFERENCES users ON DELETE CASCADE,
joined_at TIMESTAMP,
PRIMARY KEY(conversation_id, user_id)
);
CREATE TABLE IF NOT EXISTS messages (
id TEXT PRIMARY KEY,
conversation_id TEXT REFERENCES conversations ON DELETE CASCADE,
author_id TEXT REFERENCES users ON DELETE NO ACTION,
type INT,
content TEXT,
created_at TIMESTAMP
);
CREATE TABLE IF NOT EXISTS push_subscriptions (
user_id TEXT REFERENCES users ON DELETE CASCADE,
endpoint TEXT UNIQUE,
p256dh TEXT,
auth TEXT
);