-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
257 lines (223 loc) · 6.4 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
252
253
254
255
256
257
CREATE TABLE ARTIST (
nickname VARCHAR(16) UNIQUE NOT NULL,
firstName VARCHAR(20) NOT NULL,
lastName VARCHAR(20) NOT NULL,
e_mail VARCHAR(100) UNIQUE NOT NULL,
locality VARCHAR(16) NOT NULL,
bestInstrument VARCHAR(16) NOT NULL,
telephoneNumber VARCHAR(16) UNIQUE NOT NULL,
isCertified BOOLEAN NOT NULL,
isMaster BOOLEAN NOT NULL,
pass VARCHAR(128) NOT NULL,
PRIMARY KEY (nickname)
);
CREATE TABLE GENRE(
genreName VARCHAR(16) UNIQUE NOT NULL,
genreDescription VARCHAR(128) NOT NULL,
origin VARCHAR(256) NOT NULL,
PRIMARY KEY (genreName)
);
CREATE TABLE INFLUENCE(
genreName VARCHAR(16) NOT NULL,
nickname VARCHAR(16) NOT NULL,
PRIMARY KEY (genreName, nickname)
);
CREATE TABLE FOLLOW(
genreName VARCHAR(16) NOT NULL,
nickname VARCHAR(16) NOT NULL,
PRIMARY KEY (genreName, nickname)
);
CREATE TABLE DISCUSSION(
discussionID SERIAL UNIQUE,
timestampDiscussion TIMESTAMP NOT NULL,
title VARCHAR(64) NOT NULL,
average INT NOT NULL,
nickname VARCHAR(16) NOT NULL,
discussionText VARCHAR(400) NOT NULL,
PRIMARY KEY (discussionID)
);
CREATE TABLE COMMENT(
commentID SERIAL UNIQUE,
commentText VARCHAR(64) NOT NULL,
timestampComment TIMESTAMP NOT NULL,
nickname VARCHAR(16) NOT NULL,
discussionID INT NOT NULL,
PRIMARY KEY(commentID)
);
CREATE TABLE REACTION(
nickname VARCHAR(16) NOT NULL,
discussionID INT NOT NULL,
vote BOOLEAN,
dateAndTime TIMESTAMP NOT NULL,
PRIMARY KEY (nickname, discussionID)
);
CREATE TABLE HASHTAG(
hashtagName VARCHAR(20) UNIQUE NOT NULL,
PRIMARY KEY (hashtagName)
);
CREATE TABLE POST_REFERENCE(
discussionID INT NOT NULL,
hashtagName VARCHAR(20) NOT NULL,
PRIMARY KEY(discussionID, hashtagName)
);
CREATE TABLE CHAT_PARTICIPANT(
chatID INT NOT NULL,
entryDate Date NOT NULL,
exitDate Date,
nickname VARCHAR(16) NOT NULL,
PRIMARY KEY(chatID, nickname)
);
CREATE TABLE CHAT(
chatID SERIAL UNIQUE,
chatName VARCHAR(32) NOT NULL,
PRIMARY KEY(chatID)
);
CREATE TABLE MESSAGE(
messageID SERIAL UNIQUE,
chatID INT NOT NULL,
nickname VARCHAR(16) NOT NULL,
messageText VARCHAR(255) NOT NULL,
timestampMessage TIMESTAMP NOT NULL,
PRIMARY KEY(messageID)
);
CREATE TABLE BAND(
bandName VARCHAR(24) UNIQUE NOT NULL,
foundationDate DATE NOT NULL,
PRIMARY KEY(bandName)
);
CREATE TABLE ALBUM(
albumID SERIAL UNIQUE,
albumName VARCHAR(10) NOT NULL,
releaseDate DATE NOT NULL,
bandName VARCHAR(24),
nickName VARCHAR(16),
PRIMARY KEY(albumID)
);
CREATE TABLE SONG(
songID SERIAL UNIQUE,
musicTrack INT NOT NULL,
songName VARCHAR(10) NOT NULL,
duration INT NOT NULL,
albumID INT,
releaseDate DATE NOT NULL,
bandName VARCHAR(24),
nickName VARCHAR(16),
PRIMARY KEY(songID)
);
CREATE TABLE APPARTAINANCE(
genreName VARCHAR(16),
songID INT NOT NULL,
PRIMARY KEY(genreName)
);
CREATE TABLE OBSERVATION(
hashtagName VARCHAR(20) NOT NULL,
nickname VARCHAR(16) NOT NULL,
PRIMARY KEY(hashtagName, nickname)
);
CREATE TABLE BAND_MEMBER(
nickname VARCHAR(16) NOT NULL,
bandName VARCHAR(24) NOT NULL,
entryTimeStamp TIMESTAMP NOT NULL,
exitTimeStamp TIMESTAMP,
PRIMARY KEY(nickname, bandName)
);
ALTER TABLE BAND_MEMBER
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE BAND_MEMBER
ADD FOREIGN KEY (bandName) REFERENCES BAND(bandName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE FOLLOW
ADD FOREIGN KEY (genreName) REFERENCES GENRE(genreName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE FOLLOW
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE INFLUENCE
ADD FOREIGN KEY (genreName) REFERENCES GENRE(genreName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE INFLUENCE
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE COMMENT
ADD FOREIGN KEY (discussionID) REFERENCES DISCUSSION(discussionID)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE COMMENT
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE DISCUSSION
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE REACTION
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE REACTION
ADD FOREIGN KEY (discussionID) REFERENCES DISCUSSION(discussionID)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE POST_REFERENCE
ADD FOREIGN KEY (discussionID) REFERENCES DISCUSSION(discussionID)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE POST_REFERENCE
ADD FOREIGN KEY (hashtagName) REFERENCES HASHTAG(hashtagName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE OBSERVATION
ADD FOREIGN KEY (hashtagName) REFERENCES HASHTAG(hashtagName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE OBSERVATION
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE CHAT_PARTICIPANT
ADD FOREIGN KEY (nickname) REFERENCES ARTIST(nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE CHAT_PARTICIPANT
ADD FOREIGN KEY (chatID) REFERENCES CHAT(chatID)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE MESSAGE
ADD FOREIGN KEY (chatID, nickname) REFERENCES CHAT_PARTICIPANT(chatID, nickname)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE SONG
ADD FOREIGN KEY (albumID) REFERENCES ALBUM(albumID)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE SONG
ADD FOREIGN KEY (bandName) REFERENCES BAND(bandName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE SONG
ADD FOREIGN KEY (nickName) REFERENCES ARTIST(nickName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ALBUM
ADD FOREIGN KEY (bandName) REFERENCES BAND(bandName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ALBUM
ADD FOREIGN KEY (nickName) REFERENCES ARTIST(nickName)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE APPARTAINANCE
ADD FOREIGN KEY (songID) REFERENCES SONG(songID)
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE APPARTAINANCE
ADD FOREIGN KEY (genreName) REFERENCES GENRE(genreName)
ON DELETE CASCADE
ON UPDATE NO ACTION;