diff --git a/pom.xml b/pom.xml index 769a6af..7d82fb3 100644 --- a/pom.xml +++ b/pom.xml @@ -1,76 +1,88 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.5.11 - - - com.dizio1 - watchvault - 0.0.1-SNAPSHOT - watchvault - Demo project for Spring Boot - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-web - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.11 + + + com.dizio1 + watchvault + 0.0.1-SNAPSHOT + watchvault + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-web + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.16 + + + org.postgresql + postgresql + runtime + + + org.flywaydb + flyway-database-postgresql + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + - - org.postgresql - postgresql - runtime - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.security - spring-security-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/src/main/java/com/dizio1/watchvault/review/infrastructure/out/persistence/ReviewEntity.java b/src/main/java/com/dizio1/watchvault/review/infrastructure/out/persistence/ReviewEntity.java index 8d629f9..a24df2c 100644 --- a/src/main/java/com/dizio1/watchvault/review/infrastructure/out/persistence/ReviewEntity.java +++ b/src/main/java/com/dizio1/watchvault/review/infrastructure/out/persistence/ReviewEntity.java @@ -14,8 +14,10 @@ public class ReviewEntity { private Long id; @Column(nullable = false) private Long showId; + @Column(nullable = false) @Enumerated(EnumType.STRING) private ShowType showType; + @Column(nullable = false) private String title; private String description; private Integer rating; diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml index 196b22b..f2eaf02 100644 --- a/src/main/resources/application-dev.yaml +++ b/src/main/resources/application-dev.yaml @@ -7,15 +7,24 @@ spring: jpa: show-sql: true hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: format_sql: true jackson: property-naming-strategy: SNAKE_CASE + flyway: + enabled: false +management: + endpoint: + health: + show-details: always +springdoc: + api-docs: + enabled: true security: jwt: secret: ${JWT_SECRET} tmdb: base-url: ${TMDB_BASE_URL} - token: ${TMDB_TOKEN} \ No newline at end of file + token: ${TMDB_TOKEN} diff --git a/src/main/resources/application-prod.yaml b/src/main/resources/application-prod.yaml new file mode 100644 index 0000000..868a8b7 --- /dev/null +++ b/src/main/resources/application-prod.yaml @@ -0,0 +1,32 @@ +spring: + datasource: + url: ${DB_URL} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + driver-class-name: org.postgresql.Driver + jpa: + show-sql: false + hibernate: + ddl-auto: validate + properties: + hibernate: + format_sql: true + jackson: + property-naming-strategy: SNAKE_CASE + flyway: + enabled: true + validate-on-migrate: true + locations: classpath:db/migration +management: + endpoint: + health: + show-details: never +springdoc: + api-docs: + enabled: true +security: + jwt: + secret: ${JWT_SECRET} +tmdb: + base-url: ${TMDB_BASE_URL} + token: ${TMDB_TOKEN} diff --git a/src/main/resources/db/migration/V1__create_movies_table.sql b/src/main/resources/db/migration/V1__create_movies_table.sql new file mode 100644 index 0000000..8157607 --- /dev/null +++ b/src/main/resources/db/migration/V1__create_movies_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE movies +( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + title VARCHAR(255) NOT NULL UNIQUE, + directed_by VARCHAR(255), + overview TEXT, + runtime INT, + release_date DATE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__create_series_table.sql b/src/main/resources/db/migration/V2__create_series_table.sql new file mode 100644 index 0000000..e9a48a9 --- /dev/null +++ b/src/main/resources/db/migration/V2__create_series_table.sql @@ -0,0 +1,12 @@ +CREATE TABLE series +( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + title VARCHAR(255), + description TEXT NOT NULL, + created_by VARCHAR(255), + episodes INT, + seasons INT, + first_air_date DATE, + last_air_date DATE, + status VARCHAR(255) +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__create_genres_table.sql b/src/main/resources/db/migration/V3__create_genres_table.sql new file mode 100644 index 0000000..ba0fab7 --- /dev/null +++ b/src/main/resources/db/migration/V3__create_genres_table.sql @@ -0,0 +1,5 @@ +CREATE TABLE genres +( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name VARCHAR(50) NOT NULL UNIQUE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V4__create_reviews_table.sql b/src/main/resources/db/migration/V4__create_reviews_table.sql new file mode 100644 index 0000000..60edaaa --- /dev/null +++ b/src/main/resources/db/migration/V4__create_reviews_table.sql @@ -0,0 +1,10 @@ +CREATE TABLE reviews +( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + show_id BIGINT NOT NULL, + show_type VARCHAR(20) NOT NULL, + title VARCHAR(255) NOT NULL, + description TEXT, + rating INT CHECK (rating BETWEEN 1 AND 10), + reviewed_at DATE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V5__create_movies_genres_table.sql b/src/main/resources/db/migration/V5__create_movies_genres_table.sql new file mode 100644 index 0000000..fe7da26 --- /dev/null +++ b/src/main/resources/db/migration/V5__create_movies_genres_table.sql @@ -0,0 +1,17 @@ +CREATE TABLE movies_genres +( + movie_id BIGINT NOT NULL, + genre_id BIGINT NOT NULL, + + PRIMARY KEY (movie_id, genre_id), + + CONSTRAINT fk_movies_genres_movie + FOREIGN KEY (movie_id) + REFERENCES movies (id) + ON DELETE CASCADE, + + CONSTRAINT fk_movies_genres_genre + FOREIGN KEY (genre_id) + REFERENCES genres (id) + ON DELETE CASCADE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V6__create_series_genres_table.sql b/src/main/resources/db/migration/V6__create_series_genres_table.sql new file mode 100644 index 0000000..ddd34a3 --- /dev/null +++ b/src/main/resources/db/migration/V6__create_series_genres_table.sql @@ -0,0 +1,17 @@ +CREATE TABLE series_genres +( + series_id BIGINT NOT NULL, + genre_id BIGINT NOT NULL, + + PRIMARY KEY (series_id, genre_id), + + CONSTRAINT fk_series_genres_series + FOREIGN KEY (series_id) + REFERENCES series (id) + ON DELETE CASCADE, + + CONSTRAINT fk_series_genres_genres + FOREIGN KEY (genre_id) + REFERENCES genres (id) + ON DELETE CASCADE +) \ No newline at end of file diff --git a/src/main/resources/db/migration/V7__create_indexes.sql b/src/main/resources/db/migration/V7__create_indexes.sql new file mode 100644 index 0000000..485c958 --- /dev/null +++ b/src/main/resources/db/migration/V7__create_indexes.sql @@ -0,0 +1,6 @@ +-- Many to many +CREATE INDEX idx_movies_genres_movie + ON movies_genres (movie_id); + +CREATE INDEX idx_series_genres_series + ON series_genres (series_id);