Skip to content

Commit

Permalink
refactor: apply flyway
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Sep 30, 2024
1 parent 016cfca commit 52c4de0
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gymmi/entity/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Feedback {
public class Feedback extends TimeEntity{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/gymmi/entity/Logined.java
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gymmi/entity/ProfileImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/gymmi/global/FlywayConfig.java
Original file line number Diff line number Diff line change
@@ -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();
};
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ spring:
activate:
on-profile: dev

flyway:
enabled: true
baseline-on-migrate: true

jpa:
hibernate:
ddl-auto: none
Expand Down
113 changes: 113 additions & 0 deletions src/main/resources/db/migration/V240930__init.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 52c4de0

Please sign in to comment.