This repository has been archived by the owner on Sep 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema.sql
255 lines (228 loc) · 6.99 KB
/
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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
-- ImageDao
CREATE TABLE IF NOT EXISTS image
(
imageId SERIAL PRIMARY KEY,
photoBlob BYTEA
);
-- UserDao
CREATE TABLE IF NOT EXISTS users
(
userId SERIAL PRIMARY KEY,
email TEXT NOT NULL,
username TEXT NOT NULL,
password TEXT NOT NULL,
name VARCHAR(100),
enabled BOOLEAN NOT NULL,
nonLocked BOOLEAN NOT NULL,
strikes INT NOT NULL,
banDate TIMESTAMP,
imageId INT,
role INT NOT NULL,
UNIQUE (email),
UNIQUE (username),
FOREIGN KEY (imageId) REFERENCES image (imageId) ON DELETE SET NULL
);
-- MediaDao
CREATE TABLE IF NOT EXISTS media
(
mediaId SERIAL PRIMARY KEY,
type INT NOT NULL,
title VARCHAR(100) NOT NULL,
description TEXT,
image TEXT,
length INT,
releaseDate TIMESTAMP,
seasons INT,
country INT
);
-- ListsDao
CREATE TABLE IF NOT EXISTS mediaList
(
mediaListId SERIAL PRIMARY KEY,
userId INT NOT NULL,
listname TEXT NOT NULL,
description TEXT NOT NULL,
creationDate TIMESTAMP,
visibility BOOLEAN,
collaborative BOOLEAN,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS listElement
(
mediaId INT NOT NULL,
mediaListId INT NOT NULL,
FOREIGN KEY (mediaId) REFERENCES media (mediaId) ON DELETE CASCADE,
FOREIGN KEY (mediaListId) REFERENCES medialist (medialistid) ON DELETE CASCADE,
UNIQUE (mediaId, mediaListId)
);
CREATE TABLE IF NOT EXISTS forkedLists
(
originalistId INT NOT NULL,
forkedlistId INT NOT NULL,
FOREIGN KEY (originalistId) REFERENCES medialist (medialistid) ON DELETE CASCADE,
FOREIGN KEY (forkedlistId) REFERENCES medialist (medialistid) ON DELETE CASCADE
);
-- CollaborativeDao
CREATE TABLE IF NOT EXISTS collaborative
(
collabId SERIAL PRIMARY KEY,
listId INT NOT NULL,
collaboratorId INT NOT NULL,
accepted BOOLEAN,
FOREIGN KEY (listId) REFERENCES medialist (medialistid) ON DELETE CASCADE,
FOREIGN KEY (collaboratorId) REFERENCES users (userid) ON DELETE CASCADE,
UNIQUE (listId, collaboratorId)
);
-- CommentDao
CREATE TABLE IF NOT EXISTS mediacomment
(
commentId SERIAL PRIMARY KEY,
userId INT NOT NULL,
mediaId INT NOT NULL,
description TEXT,
date TIMESTAMP,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE,
FOREIGN KEY (mediaId) REFERENCES media (mediaId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS listcomment
(
commentId SERIAL PRIMARY KEY,
userId INT NOT NULL,
listId INT NOT NULL,
description TEXT,
date TIMESTAMP,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE,
FOREIGN KEY (listId) REFERENCES medialist (medialistid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS commentNotifications
(
notificationId SERIAL PRIMARY KEY,
commentId INT NOT NULL,
opened BOOLEAN DEFAULT FALSE,
FOREIGN KEY (commentId) REFERENCES listcomment (commentid) ON DELETE CASCADE
);
-- FavoriteDao
CREATE TABLE IF NOT EXISTS favoritemedia
(
userId INT NOT NULL,
mediaId INT NOT NULL,
FOREIGN KEY (mediaId) REFERENCES media (mediaId) ON DELETE CASCADE,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS favoritelists
(
userId INT NOT NULL,
mediaListId INT NOT NULL,
FOREIGN KEY (mediaListId) REFERENCES medialist (mediaListId) ON DELETE CASCADE,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE
);
-- GenreDao
CREATE TABLE IF NOT EXISTS genre
(
genreId SERIAL PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS mediaGenre
(
mediaId INT NOT NULL,
genreId INT NOT NULL,
FOREIGN KEY (mediaId) REFERENCES media (mediaid) ON DELETE CASCADE,
FOREIGN KEY (genreId) REFERENCES genre (genreId) ON DELETE CASCADE
);
-- ModeratorDao
CREATE TABLE IF NOT EXISTS modRequests
(
requestId SERIAL PRIMARY KEY,
userId INT,
date TIMESTAMP NOT NULL,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE
);
-- ReportDao
CREATE TABLE IF NOT EXISTS listReport
(
reportId SERIAL PRIMARY KEY,
listId INT NOT NULL,
reporteeId INT NOT NULL,
report TEXT NOT NULL,
date TIMESTAMP NOT NULL,
FOREIGN KEY (listId) REFERENCES mediaList (mediaListId) ON DELETE CASCADE,
FOREIGN KEY (reporteeId) REFERENCES users (userId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS listCommentReport
(
reportId SERIAL PRIMARY KEY,
commentId INT NOT NULL,
reporteeId INT NOT NULL,
report TEXT NOT NULL,
date TIMESTAMP NOT NULL,
FOREIGN KEY (commentId) REFERENCES listComment (commentId) ON DELETE CASCADE,
FOREIGN KEY (reporteeId) REFERENCES users (userId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS mediaCommentReport
(
reportId SERIAL PRIMARY KEY,
commentId INT NOT NULL,
reporteeId INT NOT NULL,
report TEXT NOT NULL,
date TIMESTAMP NOT NULL,
FOREIGN KEY (commentId) REFERENCES mediaComment (commentId) ON DELETE CASCADE,
FOREIGN KEY (reporteeId) REFERENCES users (userId) ON DELETE CASCADE
);
-- StaffDao
CREATE TABLE IF NOT EXISTS staffMember
(
staffMemberId SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
image TEXT
);
CREATE TABLE IF NOT EXISTS director
(
directorId SERIAL PRIMARY KEY,
mediaId INT NOT NULL,
staffMemberId INT NOT NULL,
FOREIGN KEY (mediaId) References media (mediaId) ON DELETE CASCADE,
FOREIGN KEY (staffMemberId) References staffMember (staffMemberId) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS crew
(
crewId SERIAL PRIMARY KEY,
mediaId INT NOT NULL,
staffMemberId INT NOT NULL,
characterName VARCHAR(100) NOT NULL,
FOREIGN KEY (mediaId) References media (mediaId) ON DELETE CASCADE,
FOREIGN KEY (staffMemberId) References staffMember (staffMemberId) ON DELETE CASCADE
);
-- StudioDao
CREATE TABLE IF NOT EXISTS studio
(
studioId SERIAL PRIMARY KEY,
name TEXT,
image TEXT
);
CREATE TABLE IF NOT EXISTS mediaStudio
(
mediaId INT NOT NULL,
studioId INT NOT NULL,
FOREIGN KEY (mediaId) REFERENCES media (mediaId),
FOREIGN KEY (studioId) REFERENCES studio (studioId)
);
-- TokenDao
CREATE TABLE IF NOT EXISTS token
(
userId INT NOT NULL,
type INT NOT NULL,
token TEXT NOT NULL,
expiryDate TIMESTAMP NOT NULL,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE
);
-- WatchDao
CREATE TABLE IF NOT EXISTS towatchmedia
(
watchedMediaId SERIAL PRIMARY KEY,
userId INT NOT NULL,
mediaId INT NOT NULL,
watchDate TIMESTAMP,
FOREIGN KEY (mediaId) REFERENCES media (mediaId) ON DELETE CASCADE,
FOREIGN KEY (userId) REFERENCES users (userId) ON DELETE CASCADE
);