Migration fixing
This commit is contained in:
parent
33c67ff4de
commit
a1f691de6a
1 changed files with 23 additions and 25 deletions
|
@ -1,5 +1,6 @@
|
||||||
PRAGMA foreign_keys = OFF;
|
PRAGMA foreign_keys = OFF;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Users;
|
||||||
DROP TABLE IF EXISTS Tickets;
|
DROP TABLE IF EXISTS Tickets;
|
||||||
DROP TABLE IF EXISTS Reservations;
|
DROP TABLE IF EXISTS Reservations;
|
||||||
DROP TABLE IF EXISTS Showings;
|
DROP TABLE IF EXISTS Showings;
|
||||||
|
@ -9,44 +10,35 @@ DROP TABLE IF EXISTS Theaters;
|
||||||
PRAGMA foreign_keys = ON;
|
PRAGMA foreign_keys = ON;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Users (
|
CREATE TABLE IF NOT EXISTS Users (
|
||||||
username VARCHAR(50) PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
name VARCHAR(100),
|
username VARCHAR(50),
|
||||||
address VARCHAR(255),
|
address VARCHAR(255),
|
||||||
telephone VARCHAR(20)
|
telephone VARCHAR(20)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Theaters (
|
CREATE TABLE IF NOT EXISTS Theaters (
|
||||||
theater_id SERIAL PRIMARY KEY,
|
theater_id INTEGER PRIMARY KEY,
|
||||||
name VARCHAR(100) UNIQUE,
|
name VARCHAR(100) UNIQUE,
|
||||||
total_seats INTEGER
|
total_seats INTEGER
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Movies (
|
CREATE TABLE IF NOT EXISTS Movies (
|
||||||
movie_id SERIAL PRIMARY KEY,
|
movie_id INTEGER PRIMARY KEY,
|
||||||
name VARCHAR(255) UNIQUE
|
name VARCHAR(255) UNIQUE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Showings (
|
CREATE TABLE IF NOT EXISTS Showings (
|
||||||
showing_id SERIAL PRIMARY KEY,
|
showing_id INTEGER PRIMARY KEY,
|
||||||
movie_id INTEGER REFERENCES Movies(movie_id),
|
movie_id INTEGER REFERENCES Movies(movie_id),
|
||||||
theater_id INTEGER REFERENCES Theaters(theater_id),
|
theater_id INTEGER REFERENCES Theaters(theater_id),
|
||||||
show_date DATE,
|
show_date DATE
|
||||||
UNIQUE(movie_id, show_date)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Reservations (
|
CREATE TABLE IF NOT EXISTS Reservations (
|
||||||
reservation_id SERIAL PRIMARY KEY,
|
reservation_id INTEGER PRIMARY KEY,
|
||||||
username VARCHAR(50) REFERENCES Users(username),
|
username VARCHAR(50) REFERENCES Users(id),
|
||||||
showing_id INTEGER REFERENCES Showings(showing_id),
|
showing_id INTEGER REFERENCES Showings(showing_id),
|
||||||
reservation_number VARCHAR(50),
|
reservation_number VARCHAR(50) UNIQUE NOT NULL DEFAULT (hex(randomblob(2))) -- 4 characters
|
||||||
FOREIGN KEY (showing_id, reservation_number) REFERENCES Tickets(showing_id, reservation_number)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Tickets (
|
|
||||||
showing_id INTEGER REFERENCES Showings(showing_id),
|
|
||||||
reservation_number VARCHAR(50),
|
|
||||||
PRIMARY KEY (showing_id, reservation_number),
|
|
||||||
FOREIGN KEY (showing_id, reservation_number) REFERENCES Reservations(showing_id, reservation_number)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO Theaters (name, total_seats) VALUES ('Theater 1', 100);
|
INSERT INTO Theaters (name, total_seats) VALUES ('Theater 1', 100);
|
||||||
|
@ -56,11 +48,17 @@ INSERT INTO Movies (name) VALUES ('Movie 1');
|
||||||
INSERT INTO Movies (name) VALUES ('Movie 2');
|
INSERT INTO Movies (name) VALUES ('Movie 2');
|
||||||
INSERT INTO Movies (name) VALUES ('Movie 3');
|
INSERT INTO Movies (name) VALUES ('Movie 3');
|
||||||
|
|
||||||
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (1, 1, '2021-01-01');
|
INSERT INTO Users (username, address, telephone) VALUES ('user1', 'address1', '1234567890');
|
||||||
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (1, 1, '2021-01-02');
|
INSERT INTO Users (username, address, telephone) VALUES ('user2', 'address2', '1234567890');
|
||||||
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (1, 2, '2021-01-01');
|
INSERT INTO Users (username, address, telephone) VALUES ('user3', 'address3', '1234567890');
|
||||||
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (2, 2, '2021-01-01');
|
|
||||||
|
|
||||||
INSERT INTO Users (username, name, address, telephone) VALUES ('user1', 'User 1', 'Address 1', '1234567890');
|
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (1, 1, '2024-04-01');
|
||||||
INSERT INTO Users (username, name, address, telephone) VALUES ('user2', 'User 2', 'Address 2', '1234567890');
|
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (2, 1, '2024-02-24');
|
||||||
INSERT INTO Users (username, name, address, telephone) VALUES ('user3', 'User 3', 'Address 3', '1234567890');
|
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (3, 1, '2024-08-12');
|
||||||
|
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (1, 2, '2024-03-04');
|
||||||
|
INSERT INTO Showings (movie_id, theater_id, show_date) VALUES (2, 2, '2024-01-10');
|
||||||
|
|
||||||
|
INSERT INTO Reservations (username, showing_id) VALUES (1, 1);
|
||||||
|
INSERT INTO Reservations (username, showing_id) VALUES (2, 2);
|
||||||
|
INSERT INTO Reservations (username, showing_id) VALUES (3, 3);
|
||||||
|
INSERT INTO Reservations (username, showing_id) VALUES (1, 4);
|
Loading…
Reference in a new issue