Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions db/flyway.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flyway]
environment = "local"
locations = ["filesystem:/C:/_elevate/Projects/java-api-migrations/db/migrations"] # Path to your migration scripts

[environments.local]
url = "jdbc:postgresql://localhost:5431/test2" # JDBC URL for localhost PostgreSQL
user = "admin"
password = "admin"
defaultSchema = true
28 changes: 28 additions & 0 deletions db/migrations/V2_0_0__create_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- V1__create_movies_table.sql

CREATE TABLE movies (
id INT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
director VARCHAR(255),
director_country VARCHAR(100),
star VARCHAR(255),
star_dob DATE,
writer VARCHAR(255),
writer_email VARCHAR(255),
filmYear INT,
genre VARCHAR(100),
score INT CHECK (score BETWEEN 0 AND 10)
);

-- Optionally insert the data from your example
INSERT INTO movies (id, title, director, director_country, star, star_dob, writer, writer_email, filmYear, genre, score) VALUES
(1, '2001: A Space Odyssey', 'Stanley Kubrick', 'USA', 'Keir Dullea', '1936-05-30', 'Arthur C Clarke', '[email protected]', 1968, 'Science Fiction', 10),
(2, 'Star Wars: A New Hope', 'George Lucas', 'USA', 'Mark Hamill', '1951-09-25', 'George Lucas', '[email protected]', 1977, 'Science Fiction', 7),
(3, 'To Kill A Mockingbird', 'Robert Mulligan', 'USA', 'Gregory Peck', '1916-04-05', 'Harper Lee', '[email protected]', 1962, 'Drama', 10),
(4, 'Titanic', 'James Cameron', 'Canada', 'Leonardo DiCaprio', '1974-11-11', 'James Cameron', '[email protected]', 1997, 'Romance', 5),
(5, 'Dr Zhivago', 'David Lean', 'UK', 'Julie Christie', '1940-04-14', 'Boris Pasternak', '[email protected]', 1965, 'Historical', 8),
(6, 'El Cid', 'Anthony Mann', 'USA', 'Charlton Heston', '1923-10-04', 'Frederick Frank', '[email protected]', 1961, 'Historical', 6),
(7, 'Voyage to Cythera', 'Theodoros Angelopoulos', 'Greece', 'Manos Katrakis', '1908-08-14', 'Theodoros Angelopoulos', '[email protected]', 1984, 'Drama', 8),
(8, 'Soldier of Orange', 'Paul Verhoeven', 'Netherlands', 'Rutger Hauer', '1944-01-23', 'Erik Hazelhoff Roelfzema', '[email protected]', 1977, 'Thriller', 8),
(9, 'Three Colours: Blue', 'Krzysztof Kieslowski', 'Poland', 'Juliette Binoche', '1964-03-09', 'Krzysztof Kieslowski', '[email protected]', 1993, 'Drama', 8),
(10, 'Cyrano de Bergerac', 'Jean-Paul Rappeneau', 'France', 'Gerard Depardieu', '1948-12-27', 'Edmond Rostand', '[email protected]', 1990, 'Historical', 9);
31 changes: 31 additions & 0 deletions db/migrations/V2_0_1__normalize.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE TABLE directors (
id SERIAL PRIMARY KEY,
directorName VARCHAR(255),
country VARCHAR(255)
);

CREATE TABLE stars (
id SERIAL PRIMARY KEY,
starName VARCHAR(255),
birthYear DATE
);

CREATE TABLE writers (
id SERIAL PRIMARY KEY,
writerName VARCHAR(255),
email VARCHAR(255)
);

CREATE TABLE films (
id SERIAL PRIMARY KEY,
title VARCHAR(255),
directorID INT,
starID INT,
writerID INT,
releaseYear INT,
genre VARCHAR(255),
score INT,
FOREIGN KEY (directorID) REFERENCES directors(id),
FOREIGN KEY (starID) REFERENCES stars(id),
FOREIGN KEY (writerID) REFERENCES writers(id)
);
25 changes: 25 additions & 0 deletions db/migrations/V2_0_2__insert_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

INSERT INTO directors (directorName, country)
SELECT DISTINCT director, director_country FROM movies;

INSERT INTO stars (starName, birthYear)
SELECT DISTINCT star, star_dob FROM movies;

INSERT INTO writers (writerName, email)
SELECT DISTINCT writer, writer_email FROM movies;

-- Populate films
INSERT INTO films (id, title, directorID, starID, writerID, releaseYear, genre, score)
SELECT
m.id,
m.title,
d.id,
s.id,
w.id,
m.filmYear,
m.genre,
m.score
FROM movies m
JOIN directors d ON m.director = d.directorName
JOIN stars s ON m.star = s.starName
JOIN writers w ON m.writer = w.writerName;
3 changes: 3 additions & 0 deletions db/migrations/V2_0_3__clear_monolithdata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

-- drop old movies table
DROP TABLE movies;