-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
31 lines (27 loc) · 902 Bytes
/
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
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(20) UNIQUE NOT NULL,
password VARCHAR(88) NOT NULL
);
CREATE TABLE submissions (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
text TEXT NOT NULL
);
CREATE TABLE ratings (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
submission_id INTEGER REFERENCES submissions(id) ON DELETE CASCADE,
rating_value INTEGER NOT NULL CHECK (rating_value >= 1 AND rating_value <= 10)
);
CREATE TABLE reviews (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
submission_id INTEGER REFERENCES submissions(id) ON DELETE CASCADE,
review TEXT NOT NULL
);
CREATE TABLE medians (
id SERIAL PRIMARY KEY,
submission_id INTEGER REFERENCES submissions(id) ON DELETE CASCADE,
median DECIMAL NOT NULL
);