· 5 years ago · Mar 11, 2020, 01:02 PM
1CREATE TABLE IF NOT EXISTS users
2(
3 id BIGINT PRIMARY KEY,
4 username VARCHAR(30) NOT NULL,
5 surname VARCHAR(30) NOT NULL
6);
7
8CREATE TABLE IF NOT EXISTS user_seats_quantity
9(
10 user_id BIGINT REFERENCES users (id) NOT NULL,
11 --SELECT COUNT(*) FROM seats GROUP BY seats.user_id
12 quantity INTEGER NOT NULL
13);
14
15CREATE TABLE IF NOT EXISTS movies
16(
17 id BIGINT PRIMARY KEY,
18 title VARCHAR(30) UNIQUE NOT NULL,
19 screening_id BIGINT REFERENCES screenings (id) NOT NULL
20);
21
22CREATE TABLE IF NOT EXISTS seats
23(
24 seat_id BIGINT PRIMARY KEY,
25 seat_number INTEGER NOT NULL,
26 user_id BIGINT REFERENCES users (id) NOT NULL,
27 is_available BOOLEAN NOT NULL,
28 screening_id BIGINT REFERENCES screenings (id) NOT NULL
29);
30
31CREATE TABLE IF NOT EXISTS reservations
32(
33 id BIGINT PRIMARY KEY,
34 expire_time timestamp NOT NULL,
35 user_id BIGINT REFERENCES users (id) NOT NULL
36);
37
38CREATE TABLE IF NOT EXISTS screenings
39(
40 id BIGINT PRIMARY KEY,
41 movie_id BIGINT REFERENCES movies (id) NOT NULL,
42 screening_time DATE NOT NULL,
43 room_number INTEGER NOT NULL,
44 ticket_price NUMERIC(15, 2) NOT NULL
45);