diff --git a/backend/build.gradle b/backend/build.gradle index 0b7b5b551..151c956eb 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -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' diff --git a/backend/src/main/java/com/cruru/applicant/domain/Applicant.java b/backend/src/main/java/com/cruru/applicant/domain/Applicant.java index fd7ae9399..bac54d23a 100644 --- a/backend/src/main/java/com/cruru/applicant/domain/Applicant.java +++ b/backend/src/main/java/com/cruru/applicant/domain/Applicant.java @@ -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; diff --git a/backend/src/main/java/com/cruru/member/domain/Member.java b/backend/src/main/java/com/cruru/member/domain/Member.java index 580f7c456..a813eba05 100644 --- a/backend/src/main/java/com/cruru/member/domain/Member.java +++ b/backend/src/main/java/com/cruru/member/domain/Member.java @@ -39,6 +39,7 @@ public class Member extends BaseEntity { private String phone; + @Column(columnDefinition = "varchar") @Enumerated(EnumType.STRING) private MemberRole role; diff --git a/backend/src/main/java/com/cruru/question/domain/Question.java b/backend/src/main/java/com/cruru/question/domain/Question.java index 99f1c7244..22501aaaa 100644 --- a/backend/src/main/java/com/cruru/question/domain/Question.java +++ b/backend/src/main/java/com/cruru/question/domain/Question.java @@ -28,6 +28,7 @@ public class Question { @Column(name = "question_id") private Long id; + @Column(columnDefinition = "varchar") @Enumerated(EnumType.STRING) private QuestionType questionType; diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 47f929d27..bfd31abdb 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -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: @@ -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: @@ -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: diff --git a/backend/src/main/resources/db/migration/V1_1__init_constraints.sql b/backend/src/main/resources/db/migration/V1_1__init_constraints.sql new file mode 100644 index 000000000..d97a03e99 --- /dev/null +++ b/backend/src/main/resources/db/migration/V1_1__init_constraints.sql @@ -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); diff --git a/backend/src/main/resources/db/migration/V1__init.sql b/backend/src/main/resources/db/migration/V1__init.sql new file mode 100644 index 000000000..5b155fdca --- /dev/null +++ b/backend/src/main/resources/db/migration/V1__init.sql @@ -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; diff --git a/backend/src/test/java/com/cruru/answer/domain/repository/AnswerRepositoryTest.java b/backend/src/test/java/com/cruru/answer/domain/repository/AnswerRepositoryTest.java index 860fe6d8b..1a36c1764 100644 --- a/backend/src/test/java/com/cruru/answer/domain/repository/AnswerRepositoryTest.java +++ b/backend/src/test/java/com/cruru/answer/domain/repository/AnswerRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/applicant/domain/repository/ApplicantRepositoryTest.java b/backend/src/test/java/com/cruru/applicant/domain/repository/ApplicantRepositoryTest.java index 530d73e9f..0d588b7c1 100644 --- a/backend/src/test/java/com/cruru/applicant/domain/repository/ApplicantRepositoryTest.java +++ b/backend/src/test/java/com/cruru/applicant/domain/repository/ApplicantRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/applyform/domain/repository/ApplyFormRepositoryTest.java b/backend/src/test/java/com/cruru/applyform/domain/repository/ApplyFormRepositoryTest.java index b1e9ecd3b..793053fdd 100644 --- a/backend/src/test/java/com/cruru/applyform/domain/repository/ApplyFormRepositoryTest.java +++ b/backend/src/test/java/com/cruru/applyform/domain/repository/ApplyFormRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/choice/domain/repository/ChoiceRepositoryTest.java b/backend/src/test/java/com/cruru/choice/domain/repository/ChoiceRepositoryTest.java index f111ef94a..bedfe4463 100644 --- a/backend/src/test/java/com/cruru/choice/domain/repository/ChoiceRepositoryTest.java +++ b/backend/src/test/java/com/cruru/choice/domain/repository/ChoiceRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/club/domain/repository/ClubRepositoryTest.java b/backend/src/test/java/com/cruru/club/domain/repository/ClubRepositoryTest.java index 85d21f519..8eb1fc660 100644 --- a/backend/src/test/java/com/cruru/club/domain/repository/ClubRepositoryTest.java +++ b/backend/src/test/java/com/cruru/club/domain/repository/ClubRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/dashboard/domain/repository/DashboardRepositoryTest.java b/backend/src/test/java/com/cruru/dashboard/domain/repository/DashboardRepositoryTest.java index edbcc7ed8..7e51dfdd9 100644 --- a/backend/src/test/java/com/cruru/dashboard/domain/repository/DashboardRepositoryTest.java +++ b/backend/src/test/java/com/cruru/dashboard/domain/repository/DashboardRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/evaluation/domain/repository/EvaluationRepositoryTest.java b/backend/src/test/java/com/cruru/evaluation/domain/repository/EvaluationRepositoryTest.java index 9ac8b4f88..b1215cb7f 100644 --- a/backend/src/test/java/com/cruru/evaluation/domain/repository/EvaluationRepositoryTest.java +++ b/backend/src/test/java/com/cruru/evaluation/domain/repository/EvaluationRepositoryTest.java @@ -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; diff --git a/backend/src/test/java/com/cruru/member/domain/repository/MemberRepositoryTest.java b/backend/src/test/java/com/cruru/member/domain/repository/MemberRepositoryTest.java index 7a8efd7b2..094152fb0 100644 --- a/backend/src/test/java/com/cruru/member/domain/repository/MemberRepositoryTest.java +++ b/backend/src/test/java/com/cruru/member/domain/repository/MemberRepositoryTest.java @@ -5,17 +5,16 @@ import com.cruru.member.domain.Member; import com.cruru.member.domain.MemberRole; +import com.cruru.util.RepositoryTest; import com.cruru.util.fixture.MemberFixture; 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; import org.springframework.dao.DataIntegrityViolationException; @DisplayName("회원 레포지토리 테스트") -@DataJpaTest -class MemberRepositoryTest { +class MemberRepositoryTest extends RepositoryTest { @Autowired private MemberRepository memberRepository; diff --git a/backend/src/test/java/com/cruru/process/domain/repository/ProcessRepositoryTest.java b/backend/src/test/java/com/cruru/process/domain/repository/ProcessRepositoryTest.java index f63ac07e2..89efe9041 100644 --- a/backend/src/test/java/com/cruru/process/domain/repository/ProcessRepositoryTest.java +++ b/backend/src/test/java/com/cruru/process/domain/repository/ProcessRepositoryTest.java @@ -5,15 +5,14 @@ import static org.assertj.core.api.Assertions.assertThat; import com.cruru.process.domain.Process; +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 ProcessRepositoryTest { +class ProcessRepositoryTest extends RepositoryTest { @Autowired private ProcessRepository processRepository; diff --git a/backend/src/test/java/com/cruru/question/domain/repository/QuestionRepositoryTest.java b/backend/src/test/java/com/cruru/question/domain/repository/QuestionRepositoryTest.java index c5d1b860e..fbe71b661 100644 --- a/backend/src/test/java/com/cruru/question/domain/repository/QuestionRepositoryTest.java +++ b/backend/src/test/java/com/cruru/question/domain/repository/QuestionRepositoryTest.java @@ -5,15 +5,14 @@ import static org.assertj.core.api.Assertions.assertThat; import com.cruru.question.domain.Question; +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 QuestionRepositoryTest { +class QuestionRepositoryTest extends RepositoryTest { @Autowired private QuestionRepository questionRepository; diff --git a/backend/src/test/java/com/cruru/util/RepositoryTest.java b/backend/src/test/java/com/cruru/util/RepositoryTest.java new file mode 100644 index 000000000..17909d595 --- /dev/null +++ b/backend/src/test/java/com/cruru/util/RepositoryTest.java @@ -0,0 +1,9 @@ +package com.cruru.util; + +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest(excludeAutoConfiguration = {FlywayAutoConfiguration.class}) +public class RepositoryTest { + +} diff --git a/backend/src/test/resources/application.yml b/backend/src/test/resources/application.yml index 4f3969653..ae44e8884 100644 --- a/backend/src/test/resources/application.yml +++ b/backend/src/test/resources/application.yml @@ -1,3 +1,25 @@ +spring: + config: + activate: + on-profile: test + h2: + console: + enabled: true + datasource: + 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 +dataloader: + enable: false base-url: applyform: www.cruru.kr/post/%d