-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.sql
34 lines (31 loc) · 1.08 KB
/
db.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
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100),
password VARCHAR(255) NOT NULL
);
CREATE TABLE posts (
post_id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(user_id) ON DELETE CASCADE,
content TEXT,
media_type VARCHAR(50),
media_url VARCHAR(255),
timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE comments (
comment_id SERIAL PRIMARY KEY,
post_id INT REFERENCES posts(post_id) ON DELETE CASCADE,
user_id INT REFERENCES users(user_id) ON DELETE CASCADE,
content TEXT,
timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE likes (
like_id SERIAL PRIMARY KEY,
post_id INT REFERENCES posts(post_id) ON DELETE CASCADE,
comment_id INT REFERENCES comments(comment_id) ON DELETE CASCADE,
user_id INT REFERENCES users(user_id) ON DELETE CASCADE,
timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT unique_user_post_like UNIQUE (user_id, post_id)
);