Skip to content

Commit

Permalink
chore-be: flyway 적용 (woowacourse-teams#444)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kwoun Ki Ho <[email protected]>
Co-authored-by: Do Yeop Kim <[email protected]>
  • Loading branch information
3 people committed Aug 16, 2024
1 parent b4a0123 commit cac525a
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 32 deletions.
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies {
// Database
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.flywaydb:flyway-core:9.22.3'
implementation 'org.flywaydb:flyway-mysql'

// Lombok
compileOnly 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Applicant extends BaseEntity {
@JoinColumn(name = "process_id")
private Process process;

@Column(columnDefinition = "varchar")
@Enumerated(EnumType.STRING)
private ApplicantState state;

Expand Down
1 change: 1 addition & 0 deletions backend/src/main/java/com/cruru/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Member extends BaseEntity {

private String phone;

@Column(columnDefinition = "varchar")
@Enumerated(EnumType.STRING)
private MemberRole role;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Question {
@Column(name = "question_id")
private Long id;

@Column(columnDefinition = "varchar")
@Enumerated(EnumType.STRING)
private QuestionType questionType;

Expand Down
13 changes: 11 additions & 2 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ spring:
console:
enabled: true
datasource:
url: jdbc:h2:mem:database
url: jdbc:h2:mem:database;MODE=MySQL;
flyway:
enabled: false
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: create-drop
defer-datasource-initialization: true
defer-datasource-initialization: false

security:
jwt:
Expand All @@ -43,6 +46,9 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ${DB_USER}
password: ${DB_PASSWORD}
flyway:
enabled: true
baseline-on-migrate: true
jpa:
show-sql: true
properties:
Expand Down Expand Up @@ -94,6 +100,9 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ${DB_USER}
password: ${DB_PASSWORD}
flyway:
enabled: true
baseline-on-migrate: true
jpa:
properties:
hibernate:
Expand Down
54 changes: 54 additions & 0 deletions backend/src/main/resources/db/migration/V1_1__init_constraints.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
ALTER TABLE answer
ADD CONSTRAINT fk_answer_to_applicant
FOREIGN KEY (applicant_id)
REFERENCES applicant(applicant_id);

ALTER TABLE answer
ADD CONSTRAINT fk_answer_to_question
FOREIGN KEY (question_id)
REFERENCES question(question_id);

ALTER TABLE applicant
ADD CONSTRAINT fk_applicant_to_process
FOREIGN KEY (process_id)
REFERENCES process(process_id);

ALTER TABLE apply_form
ADD CONSTRAINT fk_apply_form_to_dashboard
FOREIGN KEY (dashboard_id)
REFERENCES dashboard(dashboard_id);

ALTER TABLE choice
ADD CONSTRAINT fk_choice_to_question
FOREIGN KEY (question_id)
REFERENCES question(question_id);

ALTER TABLE club
ADD CONSTRAINT fk_club_to_member
FOREIGN KEY (member_id)
REFERENCES member(member_id);

ALTER TABLE dashboard
ADD CONSTRAINT fk_dashboard_to_club
FOREIGN KEY (club_id)
REFERENCES club(club_id);

ALTER TABLE evaluation
ADD CONSTRAINT fk_evaluation_to_applicant
FOREIGN KEY (applicant_id)
REFERENCES applicant(applicant_id);

ALTER TABLE evaluation
ADD CONSTRAINT fk_evaluation_to_process
FOREIGN KEY (process_id)
REFERENCES process(process_id);

ALTER TABLE process
ADD CONSTRAINT fk_process_to_dashboard
FOREIGN KEY (dashboard_id)
REFERENCES dashboard(dashboard_id);

ALTER TABLE question
ADD CONSTRAINT fk_question_to_apply_form
FOREIGN KEY (apply_form_id)
REFERENCES apply_form(apply_form_id);
125 changes: 125 additions & 0 deletions backend/src/main/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
CREATE TABLE answer
(
answer_id BIGINT NOT NULL AUTO_INCREMENT,
applicant_id BIGINT NOT NULL,
question_id BIGINT NOT NULL,
content TEXT,
PRIMARY KEY (answer_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE applicant
(
applicant_id BIGINT NOT NULL AUTO_INCREMENT,
created_date DATETIME(6),
process_id BIGINT NOT NULL,
updated_date DATETIME(6),
email VARCHAR(255),
name VARCHAR(255),
phone VARCHAR(255),
state VARCHAR(255),
PRIMARY KEY (applicant_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE apply_form
(
apply_form_id BIGINT NOT NULL AUTO_INCREMENT,
created_date DATETIME(6),
dashboard_id BIGINT NOT NULL,
end_date DATETIME(6),
start_date DATETIME(6),
updated_date DATETIME(6),
description TEXT,
title VARCHAR(1023),
url VARCHAR(1023),
PRIMARY KEY (apply_form_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE choice
(
choice_id BIGINT NOT NULL AUTO_INCREMENT,
sequence INTEGER,
question_id BIGINT NOT NULL,
content VARCHAR(1023),
PRIMARY KEY (choice_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE club
(
club_id BIGINT NOT NULL AUTO_INCREMENT,
member_id BIGINT NOT NULL,
name VARCHAR(1023),
PRIMARY KEY (club_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE dashboard
(
dashboard_id BIGINT NOT NULL AUTO_INCREMENT,
club_id BIGINT NOT NULL,
PRIMARY KEY (dashboard_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE evaluation
(
evaluation_id BIGINT NOT NULL AUTO_INCREMENT,
score INTEGER,
applicant_id BIGINT NOT NULL,
created_date DATETIME(6),
process_id BIGINT NOT NULL,
updated_date DATETIME(6),
content TEXT,
PRIMARY KEY (evaluation_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE member
(
member_id BIGINT NOT NULL AUTO_INCREMENT,
created_date DATETIME(6),
updated_date DATETIME(6),
email VARCHAR(255) UNIQUE,
password VARCHAR(2047),
phone VARCHAR(511),
role VARCHAR(255),
PRIMARY KEY (member_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE process
(
process_id BIGINT NOT NULL AUTO_INCREMENT,
sequence INTEGER,
dashboard_id BIGINT NOT NULL,
description TEXT,
name VARCHAR(255),
PRIMARY KEY (process_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

CREATE TABLE question
(
question_id BIGINT NOT NULL AUTO_INCREMENT,
required BOOLEAN,
sequence INTEGER,
apply_form_id BIGINT NOT NULL,
content TEXT,
description TEXT,
question_type VARCHAR(255),
PRIMARY KEY (question_id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.answer.domain.Answer;
import com.cruru.util.RepositoryTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("주관식 답변 레포지토리 테스트")
@DataJpaTest
class AnswerRepositoryTest {
class AnswerRepositoryTest extends RepositoryTest {

@Autowired
private AnswerRepository answerRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.applicant.domain.Applicant;
import com.cruru.util.RepositoryTest;
import com.cruru.util.fixture.ApplicantFixture;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("지원자 레포지토리 테스트")
@DataJpaTest
class ApplicantRepositoryTest {
class ApplicantRepositoryTest extends RepositoryTest {

@Autowired
private ApplicantRepository applicantRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
import static org.junit.jupiter.api.Assertions.assertAll;

import com.cruru.applyform.domain.ApplyForm;
import com.cruru.util.RepositoryTest;
import com.cruru.util.fixture.ApplyFormFixture;
import java.time.LocalDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("지원서 레포지토리 테스트")
@DataJpaTest
class ApplyFormRepositoryTest {
class ApplyFormRepositoryTest extends RepositoryTest {

@Autowired
private ApplyFormRepository applyFormRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.choice.domain.Choice;
import com.cruru.util.RepositoryTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("객관식 선택지 레포지토리 테스트")
@DataJpaTest
class ChoiceRepositoryTest {
class ChoiceRepositoryTest extends RepositoryTest {

@Autowired
private ChoiceRepository choiceRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.club.domain.Club;
import com.cruru.util.RepositoryTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("동아리 레포지토리 테스트")
@DataJpaTest
class ClubRepositoryTest {
class ClubRepositoryTest extends RepositoryTest {

@Autowired
private ClubRepository clubRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.dashboard.domain.Dashboard;
import com.cruru.util.RepositoryTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("대시보드 레포지토리 테스트")
@DataJpaTest
class DashboardRepositoryTest {
class DashboardRepositoryTest extends RepositoryTest {

@Autowired
private DashboardRepository dashboardRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.cruru.evaluation.domain.Evaluation;
import com.cruru.util.RepositoryTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

@DisplayName("평가 레포지토리 테스트")
@DataJpaTest
class EvaluationRepositoryTest {
class EvaluationRepositoryTest extends RepositoryTest {

@Autowired
private EvaluationRepository evaluationRepository;
Expand Down
Loading

0 comments on commit cac525a

Please sign in to comment.