· 5 years ago · Mar 11, 2020, 01:28 PM
1CREATE TABLE IF NOT EXISTS movies
2(
3 id BIGINT PRIMARY KEY,
4 title VARCHAR(30) UNIQUE NOT NULL,
5 screening_id BIGINT REFERENCES screenings (id) NOT NULL
6);
7
8CREATE TABLE IF NOT EXISTS seats
9(
10 id BIGINT PRIMARY KEY,
11 seat_number INTEGER NOT NULL,
12 reservation_id BIGINT REFERENCES reservations (id) NOT NULL,
13 is_available BOOLEAN NOT NULL,
14 screening_id BIGINT REFERENCES screenings (id) NOT NULL
15);
16
17CREATE TABLE IF NOT EXISTS reservations
18(
19 id BIGINT PRIMARY KEY,
20 username VARCHAR(30) NOT NULL,
21 surname VARCHAR(30) NOT NULL,
22 expire_time timestamp NOT NULL
23);
24
25CREATE TABLE IF NOT EXISTS screenings
26(
27 id BIGINT PRIMARY KEY,
28 movie_id BIGINT REFERENCES movies (id) NOT NULL,
29 screening_time DATE NOT NULL,
30 room_id BIGINT REFERENCES screening_rooms (id) NOT NULL,
31 ticket_price NUMERIC(15, 2) NOT NULL
32);
33
34CREATE TABLE IF NOT EXISTS screening_rooms
35(
36 id BIGINT PRIMARY KEY,
37 rows_id BIGINT REFERENCES rows (id) NOT NULL,
38 seats_quantity INTEGER NOT NULL,
39 seats_id BIGINT REFERENCES seats (id) NOT NULL
40);
41
42CREATE TABLE IF NOT EXISTS rows
43(
44 id BIGINT PRIMARY KEY,
45 screening_room_id BIGINT REFERENCES screening_rooms (id) NOT NULL
46)