diff --git a/build.gradle b/build.gradle index 93ce54c..c340f69 100644 --- a/build.gradle +++ b/build.gradle @@ -35,8 +35,8 @@ dependencies { testRuntimeOnly 'org.junit.platform:junit-platform-launcher' implementation 'org.mindrot:jbcrypt:0.4' -// implementation 'org.flywaydb:flyway-core' -// implementation 'org.flywaydb:flyway-mysql' + implementation 'org.flywaydb:flyway-core' + implementation 'org.flywaydb:flyway-mysql' testImplementation "org.testcontainers:testcontainers:1.20.1" testImplementation "org.testcontainers:mysql:1.20.1" testImplementation "org.testcontainers:junit-jupiter:1.20.1" diff --git a/src/main/java/gymmi/entity/Feedback.java b/src/main/java/gymmi/entity/Feedback.java index 06452fb..4d9a7c7 100644 --- a/src/main/java/gymmi/entity/Feedback.java +++ b/src/main/java/gymmi/entity/Feedback.java @@ -14,7 +14,7 @@ @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Feedback { +public class Feedback extends TimeEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/gymmi/entity/Logined.java b/src/main/java/gymmi/entity/Logined.java index 442f591..a5fecbb 100644 --- a/src/main/java/gymmi/entity/Logined.java +++ b/src/main/java/gymmi/entity/Logined.java @@ -1,19 +1,14 @@ package gymmi.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; +import jakarta.persistence.*; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Logined { +@EqualsAndHashCode(of = {"id"}, callSuper = false) +public class Logined extends TimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/gymmi/entity/ProfileImage.java b/src/main/java/gymmi/entity/ProfileImage.java index ea0eabc..2d78337 100644 --- a/src/main/java/gymmi/entity/ProfileImage.java +++ b/src/main/java/gymmi/entity/ProfileImage.java @@ -14,7 +14,7 @@ @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class ProfileImage { +public class ProfileImage extends TimeEntity { public static final String EMPTY_NAME = "default.png"; diff --git a/src/main/java/gymmi/global/FlywayConfig.java b/src/main/java/gymmi/global/FlywayConfig.java new file mode 100644 index 0000000..e39ce00 --- /dev/null +++ b/src/main/java/gymmi/global/FlywayConfig.java @@ -0,0 +1,17 @@ +package gymmi.global; + +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class FlywayConfig { + + @Bean + public FlywayMigrationStrategy flywayMigrationStrategy() { + return flyway -> { + flyway.repair(); + flyway.migrate(); + }; + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 39c43e3..916b6c4 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -3,6 +3,10 @@ spring: activate: on-profile: dev + flyway: + enabled: true + baseline-on-migrate: true + jpa: hibernate: ddl-auto: none diff --git a/src/main/resources/db/migration/V240930__init.sql b/src/main/resources/db/migration/V240930__init.sql new file mode 100644 index 0000000..d20855a --- /dev/null +++ b/src/main/resources/db/migration/V240930__init.sql @@ -0,0 +1,113 @@ +create table uuser +( + id bigint not null auto_increment primary key, + is_resigned boolean not null, + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + email varchar(255) default '' not null, + login_id varchar(255) not null, + nickname varchar(255) not null, + password varchar(255) not null, +) engine=InnoDB; + +create table feedback +( + id bigint not null auto_increment primary key, + user_id bigint not null, + content tinytext not null, + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + foreign key (user_id) references uuser (id) +) engine=InnoDB; + +create table workspace +( + goal_score integer not null, + head_count integer not null, + created_at timestamp(3) not null, + creator bigint not null, + status varchar(255) not null, + id bigint not null auto_increment primary key, + last_modified_at timestamp(3) not null, + description varchar(255) default '' not null, + name varchar(255) not null, + password varchar(255) not null, + tag varchar(255) default '' not null, + foreign key (creator) references uuser (id) +) engine=InnoDB; + +create table logined +( + id bigint not null auto_increment primary key, + user_id bigint not null unique, + refresh_token varchar(255), + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + foreign key (user_id) references uuser (id) +) engine=InnoDB; + +create table mission +( + id bigint not null auto_increment primary key, + score integer, + workspace_id bigint not null, + name varchar(255) not null, + foreign key (workspace_id) references workspace (id) +) engine=InnoDB; + +create table profile_image +( + id bigint not null auto_increment primary key, + user_id bigint not null unique, + origin_name varchar(255) not null, + stored_name varchar(255) not null, + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + foreign key (user_id) references uuser (id) +) engine=InnoDB; + +create table task +( + id bigint not null auto_increment primary key, + is_picked bit not null, + name varchar(255) not null, +) engine=InnoDB; + +create table worker +( + contributed_score integer not null, + id bigint not null auto_increment primary key, + task_id bigint unique, + user_id bigint not null, + workspace_id bigint not null, + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + unique (user_id, workspace_id), + foreign key (task_id) references task (id), + foreign key (user_id) references uuser (id), + foreign key (workspace_id) references workspace (id) +) engine=InnoDB; + +create table worked +( + created_at timestamp(3) not null, + id bigint not null auto_increment primary key, + last_modified_at timestamp(3) not null, + worker_id bigint not null, + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + primary key (id), + foreign key (worker_id) references worker (id) +) engine=InnoDB; + +create table workout_record +( + count integer not null, + id bigint not null auto_increment primary key, + mission_id bigint not null, + working_id bigint not null, + created_at timestamp(3) not null, + last_modified_at timestamp(3) not null, + foreign key (mission_id) references mission (id), + foreign key (working_id) references worked (id) +) engine=InnoDB;