-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicterDb.sql
51 lines (46 loc) · 1.4 KB
/
picterDb.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
48
49
50
51
CREATE TABLE users
(
user_id SERIAL PRIMARY KEY,
username VARCHAR(100) NOT NULL,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email_address VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
bio TEXT DEFAULT '',
profile_pic TEXT DEFAULT '',
followers INTEGER DEFAULT 0,
following INTEGER DEFAULT 0,
registered_on VARCHAR(255) NOT NULL
);
CREATE TABLE posts
(
post_id SERIAL PRIMARY KEY,
caption TEXT DEFAULT '',
image_urls TEXT [] NOT NULL,
posted_by INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
posted_on VARCHAR(255) NOT NULL,
like_count INTEGER DEFAULT 0,
comment_count INTEGER DEFAULT 0
);
CREATE TABLE likes
(
like_id SERIAL PRIMARY KEY,
post_id INTEGER NOT NULL REFERENCES posts(post_id) ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
liked_on VARCHAR(255) NOT NULL
);
CREATE TABLE comments
(
comment_id SERIAL PRIMARY KEY,
post_id INTEGER NOT NULL REFERENCES posts(post_id) ON DELETE CASCADE,
user_id INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
comment TEXT NOT NULL,
commented_on VARCHAR(255) NOT NULL
);
CREATE TABLE followers
(
follower_id SERIAL PRIMARY KEY,
follower_user INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
following_user INTEGER NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
followed_on VARCHAR(255) NOT NULL
);