-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgres.sql
47 lines (43 loc) · 1003 Bytes
/
postgres.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
40
41
42
43
44
45
46
47
CREATE TABLE users(
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
username text,
email text,
fullname text,
created_at timestamptz
);
CREATE TABLE messages(
id int PRIMARY KEY,
title text,
content text,
user_id uuid,
created_at timestamptz,
CONSTRAINT fk_user
FOREIGN KEY(user_id)
REFERENCES users(id)
);
CREATE TABLE reactions(
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
content text,
author uuid,
message_id int,
created_at timestamptz,
CONSTRAINT fk_user
FOREIGN KEY(author)
REFERENCES users(id),
CONSTRAINT fk_message
FOREIGN KEY(message_id)
REFERENCES messages(id)
);
CREATE TABLE comments(
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
comment text,
author uuid,
message_id int,
created_at timestamptz,
CONSTRAINT fk_user
FOREIGN KEY(author)
REFERENCES users(id),
CONSTRAINT fk_message
FOREIGN KEY(message_id)
REFERENCES messages(id)
);