diff --git a/pom.xml b/pom.xml
index 8929aa3..90c80d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,16 @@
spring-boot-starter-test
test
+
+
+
+ org.flywaydb
+ flyway-core
+
+
+ org.flywaydb
+ flyway-database-postgresql
+
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 2d57ae2..647fd83 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -10,10 +10,13 @@ spring.datasource.url=${POSTGRES_URL}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver
-spring.jpa.hibernate.ddl-auto=update
+spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=false
-spring.sql.init.mode=always
-spring.sql.init.schema-locations=classpath:db/schema.sql
+
+spring.flyway.enabled=true
+spring.flyway.locations=classpath:db/migrations
+spring.flyway.baseline-on-migrate=true
+spring.flyway.baseline-version=1
## Security
spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID}
diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/migrations/V1__baseline.sql
similarity index 95%
rename from src/main/resources/db/schema.sql
rename to src/main/resources/db/migrations/V1__baseline.sql
index 4796b02..3592679 100644
--- a/src/main/resources/db/schema.sql
+++ b/src/main/resources/db/migrations/V1__baseline.sql
@@ -1,7 +1,4 @@
--- DROP TABLE IF EXISTS streams;
--- DROP TABLE IF EXISTS clips;
--- DROP TABLE IF EXISTS users;
-
+-- Users Table
CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL PRIMARY KEY,
google_id VARCHAR(64),
@@ -14,6 +11,8 @@ CREATE TABLE IF NOT EXISTS users (
stream_key VARCHAR(64) NOT NULL UNIQUE
);
+
+-- Streams Table
CREATE TABLE IF NOT EXISTS streams (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT,
@@ -24,6 +23,7 @@ CREATE TABLE IF NOT EXISTS streams (
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
+-- Clips Table
CREATE TABLE IF NOT EXISTS clips (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
@@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS clips (
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
+-- VoDs Table
CREATE TABLE IF NOT EXISTS vods (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
@@ -56,6 +57,7 @@ CREATE TABLE IF NOT EXISTS vods (
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
+-- Markers Table
CREATE TABLE IF NOT EXISTS markers (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,