-
Notifications
You must be signed in to change notification settings - Fork 0
/
createtables.sql
60 lines (54 loc) · 1.53 KB
/
createtables.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
CREATE TABLE Custom_User
(
u_id DECIMAL(9, 0) NOT NULL PRIMARY KEY,
email VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(50) NOT NULL,
username VARCHAR(10) NOT NULL
);
CREATE TABLE Title
(
t_id VARCHAR(10) NOT NULL PRIMARY KEY,
name VARCHAR(500) NOT NULL,
type VARCHAR(20),
genre VARCHAR(20) ARRAY,
release_year INTEGER,
rating FLOAT,
rating_count INTEGER,
isAdult BOOLEAN
);
CREATE TABLE Person
(
p_id VARCHAR(10) NOT NULL PRIMARY KEY,
name VARCHAR(200) NOT NULL
);
CREATE TABLE Review
(
u_id DECIMAL(9, 0) NOT NULL REFERENCES Custom_User(u_id),
t_id VARCHAR(10) NOT NULL REFERENCES Title(t_id),
time TIMESTAMP NOT NULL,
rating FLOAT,
comment VARCHAR(255),
PRIMARY KEY(u_id, t_id, time)
);
CREATE TABLE Favourite
(
u_id DECIMAL(9, 0) NOT NULL REFERENCES Custom_User(u_id),
t_id VARCHAR(10) NOT NULL REFERENCES Title(t_id),
PRIMARY KEY(u_id, t_id)
);
CREATE TABLE History
(
u_id DECIMAL(9, 0) NOT NULL REFERENCES Custom_User(u_id),
t_id VARCHAR(10) NOT NULL REFERENCES Title(t_id),
time TIMESTAMP NOT NULL,
PRIMARY KEY(u_id, t_id)
);
CREATE TABLE Principals
(
t_id VARCHAR(10) NOT NULL REFERENCES Title(t_id),
ordering INTEGER NOT NULL,
p_id VARCHAR(10) NOT NULL REFERENCES Person(p_id),
category VARCHAR(30) NOT NULL,
characters VARCHAR(500),
PRIMARY KEY(t_id, ordering)
);