From d1f020f82316ee4dc46698b5b2da5952f4ac4ba1 Mon Sep 17 00:00:00 2001 From: Sunwoo-An <110546006+Sunja-An@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:38:59 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20flyway=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 711ecd5..2ffbff6 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ ext { jwtVersion = '0.13.0' passwordEncoderVersion = '6.4.5' swaggerUIVersion = '2.2.0' + flywayVersion = '11.19.0' } java { @@ -74,6 +75,10 @@ dependencies { // * Swagger UI implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${swaggerUIVersion}" + + // * Flyway + runtimeOnly "org.flywaydb:flyway-gradle-plugin:${flywayVersion}" + implementation "org.flywaydb:flyway-mysql:${flywayVersion}" } tasks.named('test') { From 65819ca191aee45289df722f54c876682fa249ba Mon Sep 17 00:00:00 2001 From: Sunwoo-An <110546006+Sunja-An@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:39:14 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20flyway=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-local.yaml | 9 ++++++++- src/main/resources/application-prod.yaml | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml index d7f2bc8..9509133 100644 --- a/src/main/resources/application-local.yaml +++ b/src/main/resources/application-local.yaml @@ -9,7 +9,7 @@ spring: password: ${LOCAL_DB_PASSWORD} jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: format_sql: true @@ -19,6 +19,13 @@ spring: h2: console: enabled: false + flyway: + enabled: true + locations: + - classpath:db/migration + baseline-on-migrate: true + baseline-version: 0 + clean-disabled: false # (Caution!) Progress in Dev Environment springdoc: swagger-ui: diff --git a/src/main/resources/application-prod.yaml b/src/main/resources/application-prod.yaml index 3f3b6c3..9720681 100644 --- a/src/main/resources/application-prod.yaml +++ b/src/main/resources/application-prod.yaml @@ -11,7 +11,7 @@ spring: jpa: hibernate: - ddl-auto: update + ddl-auto: none properties: hibernate: format_sql: false @@ -19,6 +19,13 @@ spring: dialect: org.hibernate.dialect.MySQL8Dialect open-in-view: false + flyway: + enabled: true + locations: + - classpath:db/migration + baseline-on-migrate: true + baseline-version: 0 + springdoc: swagger-ui: path: /api-test From a3e9ba595313771299f3c9b84ea7e64fae01396b Mon Sep 17 00:00:00 2001 From: Sunwoo-An <110546006+Sunja-An@users.noreply.github.com> Date: Sun, 14 Dec 2025 16:58:12 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20user-profile=20=EA=B0=84=20?= =?UTF-8?q?=EC=88=9C=ED=99=98=EC=B0=B8=EC=A1=B0=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20(#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Conflicts: # src/main/java/com/example/bak/user/domain/Profile.java # src/main/java/com/example/bak/user/domain/User.java --- build.gradle | 1 - src/main/java/com/example/bak/user/domain/Profile.java | 1 + src/main/java/com/example/bak/user/domain/User.java | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2ffbff6..ab832f7 100644 --- a/build.gradle +++ b/build.gradle @@ -77,7 +77,6 @@ dependencies { implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${swaggerUIVersion}" // * Flyway - runtimeOnly "org.flywaydb:flyway-gradle-plugin:${flywayVersion}" implementation "org.flywaydb:flyway-mysql:${flywayVersion}" } diff --git a/src/main/java/com/example/bak/user/domain/Profile.java b/src/main/java/com/example/bak/user/domain/Profile.java index a7cd109..45fb230 100644 --- a/src/main/java/com/example/bak/user/domain/Profile.java +++ b/src/main/java/com/example/bak/user/domain/Profile.java @@ -26,6 +26,7 @@ public class Profile { @Column(nullable = false) private String nickname; + @Column(name = "user_id") private Long userId; private Profile(Long id, String name, String nickname) { diff --git a/src/main/java/com/example/bak/user/domain/User.java b/src/main/java/com/example/bak/user/domain/User.java index 608a2b5..78bf3f5 100644 --- a/src/main/java/com/example/bak/user/domain/User.java +++ b/src/main/java/com/example/bak/user/domain/User.java @@ -30,6 +30,7 @@ public class User { @Column(nullable = false) private String password; + @Column(name = "profile_id") private Long profileId; @Enumerated(EnumType.STRING) From 3b3f86641af3b06f85885040f2f33442b7a692af Mon Sep 17 00:00:00 2001 From: Sunwoo-An <110546006+Sunja-An@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:39:40 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20flyway=20version=201=20schema?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=93=B1=EB=A1=9D=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/db/migration/V1__init.sql | 100 +++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/main/resources/db/migration/V1__init.sql diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql new file mode 100644 index 0000000..55d84ed --- /dev/null +++ b/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,100 @@ +-- Drop tables if they exist (in reverse order of dependencies) +DROP TABLE IF EXISTS private_messages; +DROP TABLE IF EXISTS feed_comments; +DROP TABLE IF EXISTS feeds; +DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS profiles; +DROP TABLE IF EXISTS communities; +DROP TABLE IF EXISTS companies; + +-- Create companies table +CREATE TABLE companies +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + career_link VARCHAR(500) NOT NULL, + logo_url VARCHAR(500) NOT NULL, + description TEXT NOT NULL +); + +-- Create communities table +CREATE TABLE communities +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + job_group VARCHAR(255) NOT NULL, + company_id BIGINT, + CONSTRAINT fk_communities_company FOREIGN KEY (company_id) REFERENCES companies (id) +); + +-- Create profiles table (without foreign key initially due to circular reference) +CREATE TABLE profiles +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + nickname VARCHAR(255) NOT NULL, + user_id BIGINT +); + +-- Create users table +CREATE TABLE users +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + email VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + role VARCHAR(50) DEFAULT 'NORMAL', + profile_id BIGINT NOT NULL, + CONSTRAINT fk_users_profile FOREIGN KEY (profile_id) REFERENCES profiles (id) +); + +-- Add foreign key constraint to profiles table after users table is created +ALTER TABLE profiles + ADD CONSTRAINT fk_profiles_user FOREIGN KEY (user_id) REFERENCES users (id); + +-- Create feeds table +CREATE TABLE feeds +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(255) NOT NULL, + content TEXT NOT NULL, + community_id BIGINT, + author_id BIGINT, + CONSTRAINT fk_feeds_community FOREIGN KEY (community_id) REFERENCES communities (id), + CONSTRAINT fk_feeds_author FOREIGN KEY (author_id) REFERENCES users (id) +); + +-- Create feed_comments table +CREATE TABLE feed_comments +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + comment VARCHAR(1000) NOT NULL, + author_id BIGINT, + feed_id BIGINT, + CONSTRAINT fk_feed_comments_author FOREIGN KEY (author_id) REFERENCES users (id), + CONSTRAINT fk_feed_comments_feed FOREIGN KEY (feed_id) REFERENCES feeds (id) +); + +-- Create private_messages table +CREATE TABLE private_messages +( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + sender_id BIGINT NOT NULL, + receiver_id BIGINT NOT NULL, + content VARCHAR(1000) NOT NULL, + read_at DATETIME, + deleted_at_by_sender DATETIME, + deleted_at_by_receiver DATETIME, + created_at DATETIME NOT NULL, + CONSTRAINT fk_private_messages_sender FOREIGN KEY (sender_id) REFERENCES users (id), + CONSTRAINT fk_private_messages_receiver FOREIGN KEY (receiver_id) REFERENCES users (id) +); + +-- Create indexes for better query performance +CREATE INDEX idx_users_email ON users (email); +CREATE INDEX idx_feeds_author ON feeds (author_id); +CREATE INDEX idx_feeds_community ON feeds (community_id); +CREATE INDEX idx_feed_comments_feed ON feed_comments (feed_id); +CREATE INDEX idx_feed_comments_author ON feed_comments (author_id); +CREATE INDEX idx_private_messages_sender ON private_messages (sender_id); +CREATE INDEX idx_private_messages_receiver ON private_messages (receiver_id); +CREATE INDEX idx_communities_company ON communities (company_id); From 9afd0ed73bd0a2a263d3b1216c8183e71211f1f1 Mon Sep 17 00:00:00 2001 From: Sunwoo-An <110546006+Sunja-An@users.noreply.github.com> Date: Fri, 12 Dec 2025 16:42:08 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20local=20=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-local.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml index 9509133..eeb0acf 100644 --- a/src/main/resources/application-local.yaml +++ b/src/main/resources/application-local.yaml @@ -9,7 +9,7 @@ spring: password: ${LOCAL_DB_PASSWORD} jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: format_sql: true From 7c6a13ccd9c0fed26132971fde6e536a5c15d296 Mon Sep 17 00:00:00 2001 From: Sunwoo-An <110546006+Sunja-An@users.noreply.github.com> Date: Sun, 14 Dec 2025 17:06:37 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Chore:=20Schmea=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20Domain=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20Table=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/db/migration/V1__init.sql | 51 ++++++-------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql index 55d84ed..a54282f 100644 --- a/src/main/resources/db/migration/V1__init.sql +++ b/src/main/resources/db/migration/V1__init.sql @@ -1,12 +1,3 @@ --- Drop tables if they exist (in reverse order of dependencies) -DROP TABLE IF EXISTS private_messages; -DROP TABLE IF EXISTS feed_comments; -DROP TABLE IF EXISTS feeds; -DROP TABLE IF EXISTS users; -DROP TABLE IF EXISTS profiles; -DROP TABLE IF EXISTS communities; -DROP TABLE IF EXISTS companies; - -- Create companies table CREATE TABLE companies ( @@ -23,11 +14,10 @@ CREATE TABLE communities id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, job_group VARCHAR(255) NOT NULL, - company_id BIGINT, - CONSTRAINT fk_communities_company FOREIGN KEY (company_id) REFERENCES companies (id) + company_id BIGINT ); --- Create profiles table (without foreign key initially due to circular reference) +-- Create profiles table CREATE TABLE profiles ( id BIGINT AUTO_INCREMENT PRIMARY KEY, @@ -43,35 +33,27 @@ CREATE TABLE users email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, role VARCHAR(50) DEFAULT 'NORMAL', - profile_id BIGINT NOT NULL, - CONSTRAINT fk_users_profile FOREIGN KEY (profile_id) REFERENCES profiles (id) + profile_id BIGINT NOT NULL ); --- Add foreign key constraint to profiles table after users table is created -ALTER TABLE profiles - ADD CONSTRAINT fk_profiles_user FOREIGN KEY (user_id) REFERENCES users (id); - -- Create feeds table CREATE TABLE feeds ( id BIGINT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, content TEXT NOT NULL, - community_id BIGINT, - author_id BIGINT, - CONSTRAINT fk_feeds_community FOREIGN KEY (community_id) REFERENCES communities (id), - CONSTRAINT fk_feeds_author FOREIGN KEY (author_id) REFERENCES users (id) + community_id BIGINT NOT NULL, + author_id BIGINT NOT NULL ); --- Create feed_comments table -CREATE TABLE feed_comments +-- Create comments table +CREATE TABLE comments ( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(1000) NOT NULL, - author_id BIGINT, - feed_id BIGINT, - CONSTRAINT fk_feed_comments_author FOREIGN KEY (author_id) REFERENCES users (id), - CONSTRAINT fk_feed_comments_feed FOREIGN KEY (feed_id) REFERENCES feeds (id) + id BIGINT AUTO_INCREMENT PRIMARY KEY, + feed_id BIGINT NOT NULL, + author_id BIGINT NOT NULL, + author_nickname VARCHAR(255) NOT NULL, + content VARCHAR(1000) NOT NULL ); -- Create private_messages table @@ -84,17 +66,16 @@ CREATE TABLE private_messages read_at DATETIME, deleted_at_by_sender DATETIME, deleted_at_by_receiver DATETIME, - created_at DATETIME NOT NULL, - CONSTRAINT fk_private_messages_sender FOREIGN KEY (sender_id) REFERENCES users (id), - CONSTRAINT fk_private_messages_receiver FOREIGN KEY (receiver_id) REFERENCES users (id) + created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) ); -- Create indexes for better query performance CREATE INDEX idx_users_email ON users (email); CREATE INDEX idx_feeds_author ON feeds (author_id); CREATE INDEX idx_feeds_community ON feeds (community_id); -CREATE INDEX idx_feed_comments_feed ON feed_comments (feed_id); -CREATE INDEX idx_feed_comments_author ON feed_comments (author_id); +CREATE INDEX idx_comments_feed ON comments (feed_id); +CREATE INDEX idx_comments_author ON comments (author_id); CREATE INDEX idx_private_messages_sender ON private_messages (sender_id); CREATE INDEX idx_private_messages_receiver ON private_messages (receiver_id); CREATE INDEX idx_communities_company ON communities (company_id);