diff --git a/pom.xml b/pom.xml index 6b587ef..b89e8e6 100644 --- a/pom.xml +++ b/pom.xml @@ -44,14 +44,22 @@ org.springframework.boot spring-boot-starter-webmvc - org.projectlombok lombok 1.18.40 provided - + + org.flywaydb + flyway-database-postgresql + 12.0.3 + runtime + + + org.springframework.boot + spring-boot-starter-flyway + org.postgresql postgresql @@ -81,6 +89,17 @@ org.springframework.boot spring-boot-maven-plugin + + org.flywaydb + flyway-maven-plugin + 12.0.1 + + jdbc:postgresql://127.0.0.1:5432/videos + postgres + 5995 + false + + diff --git a/src/main/java/com/example/video_downloader/VideoDownloaderApplication.java b/src/main/java/com/example/video_downloader/VideoDownloaderApplication.java index 3b61d97..18b9f0b 100644 --- a/src/main/java/com/example/video_downloader/VideoDownloaderApplication.java +++ b/src/main/java/com/example/video_downloader/VideoDownloaderApplication.java @@ -10,4 +10,4 @@ public class VideoDownloaderApplication { SpringApplication.run(VideoDownloaderApplication.class, args); } -} +} \ No newline at end of file diff --git a/src/main/java/com/example/video_downloader/entity/Creator.java b/src/main/java/com/example/video_downloader/entity/Creator.java index 6357207..7174c01 100644 --- a/src/main/java/com/example/video_downloader/entity/Creator.java +++ b/src/main/java/com/example/video_downloader/entity/Creator.java @@ -9,7 +9,7 @@ import java.util.List; @Entity public class Creator { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; diff --git a/src/main/java/com/example/video_downloader/entity/Playlist.java b/src/main/java/com/example/video_downloader/entity/Playlist.java index b3b7b32..2bdef15 100644 --- a/src/main/java/com/example/video_downloader/entity/Playlist.java +++ b/src/main/java/com/example/video_downloader/entity/Playlist.java @@ -13,10 +13,10 @@ import java.util.List; public class Playlist { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column + @Column(name = "playlist_name", nullable = false) private String playlistName; @Column diff --git a/src/main/java/com/example/video_downloader/entity/Video.java b/src/main/java/com/example/video_downloader/entity/Video.java index 29dd230..861dc7e 100644 --- a/src/main/java/com/example/video_downloader/entity/Video.java +++ b/src/main/java/com/example/video_downloader/entity/Video.java @@ -14,17 +14,21 @@ import java.util.List; @Table(name = "videos") public class Video { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String url; private String name; + + @Column(name = "upload_date") private String uploadDate; + private String duration; @Enumerated(EnumType.STRING) private StatusEnum status; + @Column(name="full_path") private String fullPath; @ManyToMany diff --git a/src/main/java/com/example/video_downloader/services/YTDLPService.java b/src/main/java/com/example/video_downloader/services/YTDLPService.java index e04e284..4f546a1 100644 --- a/src/main/java/com/example/video_downloader/services/YTDLPService.java +++ b/src/main/java/com/example/video_downloader/services/YTDLPService.java @@ -38,7 +38,6 @@ public class YTDLPService { public void processPlaylist() throws IOException, InterruptedException { List playlists = playlistRepository.findByStatus(StatusEnum.NEW); - System.out.println("Am I slow?"); for(Playlist playlist : playlists) { String urls = processService.execute("yt-dlp", "--force-ipv4", "--flat-playlist", "--print", "webpage_url", playlist.getUrl()); for(String url : urls.split("\\n")){ diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cc208ff..24808a0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,4 +2,8 @@ spring.application.name=video_downloader spring.datasource.url = jdbc:postgresql://127.0.0.1:5432/videos spring.datasource.username = postgres spring.datasource.password = 5995 -spring.jpa.hibernate.ddl-auto = create-drop \ No newline at end of file +spring.jpa.hibernate.ddl-auto = none +logging.level.org.flywaydb=DEBUG +logging.level.org.springframework.boot.autoconfigure.flyway=DEBUG +spring.flyway.enabled=true +spring.flyway.baseline-on-migrate=true diff --git a/src/main/resources/db/migration/V1__create_table_playlist.sql b/src/main/resources/db/migration/V1__create_table_playlist.sql new file mode 100644 index 0000000..ac4b719 --- /dev/null +++ b/src/main/resources/db/migration/V1__create_table_playlist.sql @@ -0,0 +1,6 @@ +CREATE TABLE playlists ( +id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, +playlist_name VARCHAR(100) NOT NULL, +url VARCHAR(200) NOT NULL, +status VARCHAR(10) NOT NULL +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__create_table_videos.sql b/src/main/resources/db/migration/V2__create_table_videos.sql new file mode 100644 index 0000000..e899599 --- /dev/null +++ b/src/main/resources/db/migration/V2__create_table_videos.sql @@ -0,0 +1,9 @@ +CREATE TABLE videos ( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name VARCHAR(200), + url VARCHAR(200) NOT NULL, + upload_date VARCHAR(100), + duration VARCHAR(10), + status VARCHAR(10) NOT NULL, + full_path VARCHAR(100) +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__create_table_creator.sql b/src/main/resources/db/migration/V3__create_table_creator.sql new file mode 100644 index 0000000..2e5ef98 --- /dev/null +++ b/src/main/resources/db/migration/V3__create_table_creator.sql @@ -0,0 +1,5 @@ +CREATE TABLE creator ( + id BIGSERIAL PRIMARY KEY, + name VARCHAR(200) NOT NULL, + url VARCHAR(200) NOT NULL +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V4__create_table_video_playlist.sql b/src/main/resources/db/migration/V4__create_table_video_playlist.sql new file mode 100644 index 0000000..a251b8b --- /dev/null +++ b/src/main/resources/db/migration/V4__create_table_video_playlist.sql @@ -0,0 +1,7 @@ +CREATE TABLE video_playlist ( + video_id BIGINT NOT NULL, + playlist_id BIGINT NOT NULL, + PRIMARY KEY (video_id, playlist_id), + FOREIGN KEY (video_id) REFERENCES videos(id) ON DELETE CASCADE, + FOREIGN KEY (playlist_id) REFERENCES playlists(id) ON DELETE CASCADE +); \ No newline at end of file diff --git a/src/main/resources/db/migration/V5__alter_table_videos.sql b/src/main/resources/db/migration/V5__alter_table_videos.sql new file mode 100644 index 0000000..c67d281 --- /dev/null +++ b/src/main/resources/db/migration/V5__alter_table_videos.sql @@ -0,0 +1,4 @@ +ALTER TABLE videos +ADD COLUMN creator_id BIGINT, +ADD CONSTRAINT fk_videos_creator FOREIGN KEY (creator_id) REFERENCES creator(id) +