· 5 years ago · Mar 12, 2020, 07:26 PM
1CREATE TABLE IF NOT EXISTS reservations
2(
3 id BIGINT PRIMARY KEY,
4 first_name VARCHAR(30) NOT NULL,
5 last_name VARCHAR(30) NOT NULL,
6 expire_time timestamp NOT NULL
7);
8
9CREATE TABLE IF NOT EXISTS rooms
10(
11 id BIGINT PRIMARY KEY,
12 room_name VARCHAR(30) NOT NULL
13);
14
15CREATE TABLE IF NOT EXISTS screenings
16(
17 id BIGINT PRIMARY KEY,
18 movie_title VARCHAR(30) NOT NULL,
19 screening_time TIMESTAMP NOT NULL,
20 room_id BIGINT REFERENCES rooms (id) NOT NULL,
21 reservation_id BIGINT REFERENCES reservations (id) NOT NULL,
22 ticket_price NUMERIC(15, 2) NOT NULL
23);
24
25CREATE TABLE IF NOT EXISTS seats
26(
27 seat_number INTEGER NOT NULL,
28 "row_number" INTEGER NOT NULL,
29 room_id BIGINT REFERENCES rooms (id) NOT NULL,
30 PRIMARY KEY (seat_number, "row_number", room_id)
31);
32
33CREATE TABLE IF NOT EXISTS reserved_seats
34(
35 seat_number BIGINT NOT NULL,
36 "row_number" BIGINT NOT NULL,
37 reservation_id BIGINT REFERENCES reservations (id) NOT NULL,
38 screening_id BIGINT REFERENCES screenings (id) NOT NULL,
39 PRIMARY KEY (seat_number, "row_number", screening_id)
40);