From d732cb203734e1e1296ce0415ee95594a1bfc450 Mon Sep 17 00:00:00 2001 From: Roman Mager Date: Sun, 1 Sep 2024 18:46:19 +0300 Subject: [PATCH 01/27] Add Liquibase dependency --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index 09f1dc4..342559f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,6 +33,7 @@ dependencies { // Data Access implementation("org.springframework.boot:spring-boot-starter-data-jpa") + implementation("org.liquibase:liquibase-core") runtimeOnly("org.postgresql:postgresql") // Dev From b7203fd902c5c376b45755e6aca88de28e3a52b9 Mon Sep 17 00:00:00 2001 From: Roman Mager Date: Sat, 7 Sep 2024 10:22:36 +0300 Subject: [PATCH 02/27] Add Liquibase migration to init schema & master changelog --- .../db/changelog/db.changelog-master.yaml | 3 ++ .../db/changelog/db.changeset-init-schema.sql | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/resources/db/changelog/db.changelog-master.yaml create mode 100644 src/main/resources/db/changelog/db.changeset-init-schema.sql diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml new file mode 100644 index 0000000..1dc8a89 --- /dev/null +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -0,0 +1,3 @@ +databaseChangeLog: + - include: + file: /db/changelog/db.changeset-init-schema.sql diff --git a/src/main/resources/db/changelog/db.changeset-init-schema.sql b/src/main/resources/db/changelog/db.changeset-init-schema.sql new file mode 100644 index 0000000..c1fed7f --- /dev/null +++ b/src/main/resources/db/changelog/db.changeset-init-schema.sql @@ -0,0 +1,35 @@ +--liquibase formatted sql + +-- changeset Roman Maher:1 +CREATE TABLE IF NOT EXISTS playlists +( + id BIGSERIAL PRIMARY KEY NOT NULL, + name VARCHAR(255) NOT NULL, + description TEXT, + status VARCHAR +); + +-- changeset Roman Maher:2 +CREATE TABLE IF NOT EXISTS videos +( + id BIGSERIAL PRIMARY KEY NOT NULL, + youtube_id VARCHAR UNIQUE NOT NULL, + import_date DATE, + playlist_id BIGSERIAL NOT NULL, + + CONSTRAINT fk_playlist_id_playlists FOREIGN KEY (playlist_id) REFERENCES playlists (id), + CONSTRAINT unq UNIQUE (youtube_id) +); + +-- changeset Roman Maher:3 +CREATE TABLE IF NOT EXISTS video_data +( + id BIGSERIAL PRIMARY KEY NOT NULL, + title VARCHAR, + description TEXT, + channel_name VARCHAR, + tags VARCHAR, + video_id BIGSERIAL NOT NULL, + + CONSTRAINT fk_video_id_videos FOREIGN KEY (video_id) REFERENCES videos (id) ON DELETE CASCADE +); From 526f049bf7b676e58b07be37b24f1aa6aa72c863 Mon Sep 17 00:00:00 2001 From: Roman Mager Date: Sat, 7 Sep 2024 10:22:58 +0300 Subject: [PATCH 03/27] Configure Liquibase to work with Spring --- src/main/resources/application.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c7200c3..08d0294 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -33,6 +33,11 @@ spring: password: ${POSTGRES_PASSWORD} driver-class-name: org.postgresql.Driver + liquibase: + change-log: classpath:db/changelog/db.changelog-master.yaml + enabled: true + default-schema: ypm + jpa: database-platform: org.hibernate.dialect.PostgreSQLDialect show-sql: true From 62ac53e479eeed527f2bdc49a7aee758e62f160a Mon Sep 17 00:00:00 2001 From: Roman Mager Date: Sat, 7 Sep 2024 10:23:39 +0300 Subject: [PATCH 04/27] Add entities representing DB tables --- .../com/ypm/persistence/entity/Playlist.java | 32 +++++++++++++ .../com/ypm/persistence/entity/Video.java | 45 +++++++++++++++++++ .../com/ypm/persistence/entity/VideoData.java | 42 +++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/main/java/com/ypm/persistence/entity/Playlist.java create mode 100644 src/main/java/com/ypm/persistence/entity/Video.java create mode 100644 src/main/java/com/ypm/persistence/entity/VideoData.java diff --git a/src/main/java/com/ypm/persistence/entity/Playlist.java b/src/main/java/com/ypm/persistence/entity/Playlist.java new file mode 100644 index 0000000..5071b1e --- /dev/null +++ b/src/main/java/com/ypm/persistence/entity/Playlist.java @@ -0,0 +1,32 @@ +package com.ypm.persistence.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.util.LinkedHashSet; +import java.util.Set; + +@Getter +@Setter +@Entity +@Table(name = "playlists", schema = "ypm") +public class Playlist { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false) + private Long id; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "description", length = Integer.MAX_VALUE) + private String description; + + @Column(name = "status", length = Integer.MAX_VALUE) + private String status; + + @OneToMany(mappedBy = "playlist") + private Set