forked from ganadhish1999/SAGA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tables.sql
137 lines (116 loc) · 3.52 KB
/
create_tables.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
CREATE TABLE users (
user_id BIGSERIAL NOT NULL PRIMARY KEY,
username VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(150) NOT NULL,
password CHAR(60) NOT NULL,
dob DATE NOT NULL,
profile_image_name text,
UNIQUE(email),
UNIQUE (username)
);
CREATE TABLE user_about(
about TEXT,
user_id BIGINT REFERENCES users(user_id)
);
CREATE TABLE user_interest (
interest TEXT,
user_id BIGINT REFERENCES users(user_id)
);
CREATE TABLE user_qualification (
qualification TEXT,
user_id BIGINT REFERENCES users(user_id)
);
CREATE TABLE feedback (
feedback_id BIGSERIAL NOT NULL PRIMARY KEY,
content TEXT NOT NULL,
time_of_feedback TIMESTAMP,
user_id BIGINT REFERENCES users(user_id)
);
CREATE TABLE subforum (
subforum_id BIGSERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
time_of_creation TIMESTAMP,
creator_id BIGINT REFERENCES users(user_id),
UNIQUE(name)
);
CREATE TABLE community (
community_id BIGSERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
time_of_creation TIMESTAMP,
creator_id BIGINT REFERENCES users(user_id),
UNIQUE(name)
);
CREATE TABLE pending_requests (
user_id BIGINT REFERENCES users(user_id),
community_id BIGINT REFERENCES community(community_id)
);
--to display followed subforums
CREATE TABLE user_subforum (
user_id BIGINT REFERENCES users(user_id),
subforum_id BIGINT REFERENCES subforum(subforum_id)
);
--to display followed community
CREATE TABLE user_community (
user_id BIGINT REFERENCES users(user_id),
community_id BIGINT REFERENCES community(community_id)
);
CREATE TABLE pending_requests (
user_id BIGINT REFERENCES users(user_id),
community_id BIGINT REFERENCES community(community_id)
);
CREATE TABLE post (
post_id BIGSERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
time_of_creation TIMESTAMP,
upvotes INT DEFAULT 0,
downvotes INT DEFAULT 0,
author_id BIGINT REFERENCES users(user_id),
subforum_id BIGINT REFERENCES subforum(subforum_id),
community_id BIGINT REFERENCES community(community_id)
);
CREATE TABLE post_file (
file_name text NOT NULL,
post_id BIGINT REFERENCES post(post_id)
);
CREATE TABLE comment (
comment_id BIGSERIAL NOT NULL PRIMARY KEY,
content TEXT NOT NULL,
time_of_creation TIMESTAMP,
upvotes INT DEFAULT 0,
downvotes INT DEFAULT 0,
author_id BIGINT REFERENCES users(user_id),
post_id BIGINT REFERENCES post(post_id)
);
CREATE TABLE child_comment (
comment_id BIGSERIAL NOT NULL PRIMARY KEY,
content TEXT NOT NULL,
time_of_creation TIMESTAMP,
upvotes INT DEFAULT 0,
downvotes INT DEFAULT 0,
author_id BIGINT REFERENCES users(user_id),
parent_comment_id BIGINT REFERENCES comment(comment_id) DEFAULT null
);
CREATE TABLE category (
category_name TEXT NOT NULL,
post_id BIGINT REFERENCES post(post_id),
subforum_id BIGINT REFERENCES subforum(subforum_id)
);
CREATE TABLE chat (
chat_id BIGSERIAL NOT NULL PRIMARY KEY,
time_of_creation TIMESTAMP,
user1 VARCHAR(50) NOT NULL REFERENCES users(username),
user2 VARCHAR(50) NOT NULL REFERENCES users(username)
);
CREATE TABLE message (
message_id BIGSERIAL NOT NULL PRIMARY KEY,
content TEXT NOT NULL,
message_timestamp TIMESTAMP,
sender VARCHAR(50) REFERENCES users(username),
receiver VARCHAR(50) REFERENCES users(username),
chat_id BIGINT REFERENCES chat(chat_id)
);