diff --git a/backend/build.gradle b/backend/build.gradle index d28b12bcd..d36481f4e 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -43,6 +43,10 @@ dependencies { // Mockito testImplementation 'org.mockito:mockito-inline' + + // Flyway + implementation 'org.flywaydb:flyway-core' + implementation 'org.flywaydb:flyway-mysql' } tasks.named('test') { diff --git a/backend/docker/docker-compose.yml b/backend/docker/docker-compose.yml new file mode 100644 index 000000000..03d6579cf --- /dev/null +++ b/backend/docker/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.8" +services: + db: + image: mysql:8.0.33 + container_name: festago-local-db + restart: always + ports: + - "13306:3306" + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: festago + MYSQL_USER: festago + MYSQL_PASSWORD: festago + TZ: Asia/Seoul + command: [ "mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_general_ci" ] diff --git a/backend/src/main/java/com/festago/auth/domain/Admin.java b/backend/src/main/java/com/festago/auth/domain/Admin.java index abf4530c5..60aec0c40 100644 --- a/backend/src/main/java/com/festago/auth/domain/Admin.java +++ b/backend/src/main/java/com/festago/auth/domain/Admin.java @@ -1,12 +1,13 @@ package com.festago.auth.domain; +import com.festago.domain.BaseTimeEntity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; @Entity -public class Admin { +public class Admin extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/backend/src/main/java/com/festago/domain/School.java b/backend/src/main/java/com/festago/domain/School.java index 6e701a961..993fc98ce 100644 --- a/backend/src/main/java/com/festago/domain/School.java +++ b/backend/src/main/java/com/festago/domain/School.java @@ -10,7 +10,7 @@ import jakarta.validation.constraints.Size; @Entity -public class School { +public class School extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/backend/src/main/java/com/festago/domain/Student.java b/backend/src/main/java/com/festago/domain/Student.java index 768b0e462..69b10ff53 100644 --- a/backend/src/main/java/com/festago/domain/Student.java +++ b/backend/src/main/java/com/festago/domain/Student.java @@ -13,7 +13,7 @@ import jakarta.validation.constraints.Size; @Entity -public class Student { +public class Student extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/backend/src/main/resources/application-local.yml b/backend/src/main/resources/application-local.yml index e5c6d52bd..ddf517560 100644 --- a/backend/src/main/resources/application-local.yml +++ b/backend/src/main/resources/application-local.yml @@ -1,19 +1,21 @@ spring: datasource: - hikari: - jdbc-url: jdbc:h2:~/festago;MODE=MYSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - username: sa + url: jdbc:mysql://localhost:13306/festago + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver jpa: properties: hibernate: format_sql: true show-sql: true hibernate: - ddl-auto: create + ddl-auto: validate open-in-view: false - h2: - console: - enabled: true + flyway: + enabled: true + baseline-on-migrate: true + baseline-version: 1 logging: file: 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..3622ca577 --- /dev/null +++ b/backend/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,195 @@ +create table if not exists festival +( + id bigint not null auto_increment, + created_at datetime(6), + updated_at datetime(6), + end_date date, + name varchar(255), + start_date date, + thumbnail varchar(255), + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists member +( + id bigint not null auto_increment, + created_at datetime(6), + updated_at datetime(6), + deleted_at datetime(6), + nickname varchar(255), + profile_image varchar(255), + social_id varchar(255), + social_type varchar(255), + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists member_ticket +( + id bigint not null auto_increment, + created_at datetime(6), + updated_at datetime(6), + entry_state varchar(255), + entry_time datetime(6), + number integer not null, + ticket_type varchar(255), + owner_id bigint, + stage_id bigint, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists stage +( + id bigint not null auto_increment, + created_at datetime(6), + updated_at datetime(6), + line_up varchar(255), + start_time datetime(6) not null, + ticket_open_time datetime(6), + festival_id bigint, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists ticket +( + id bigint not null auto_increment, + created_at datetime(6), + updated_at datetime(6), + ticket_type varchar(255), + stage_id bigint, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists ticket_amount +( + ticket_id bigint not null, + created_at datetime(6), + updated_at datetime(6), + reserved_amount integer not null, + total_amount integer not null, + primary key (ticket_id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists ticket_entry_time +( + id bigint not null auto_increment, + created_at datetime(6), + updated_at datetime(6), + amount integer, + entry_time datetime(6), + ticket_id bigint, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists school +( + id bigint not null auto_increment, + created_at datetime null, + updated_at datetime null, + domain varchar(50) not null, + name varchar(255) not null, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists student +( + id bigint not null auto_increment, + created_at datetime null, + updated_at datetime null, + username varchar(255) not null, + member_id bigint not null, + school_id bigint not null, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists student_code +( + id bigint auto_increment not null, + created_at datetime null, + updated_at datetime null, + school_id bigint null, + member_id bigint null, + code varchar(255) null, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +create table if not exists admin +( + id bigint auto_increment not null, + created_at datetime null, + updated_at datetime null, + username varchar(255) null, + password varchar(255) null, + primary key (id) +) engine innodb + default charset = utf8mb4 + collate = utf8mb4_0900_ai_ci; + +alter table member_ticket + add constraint fk_member_ticket__member + foreign key (owner_id) + references member (id); + +alter table member_ticket + add constraint fk_member_ticket__stage + foreign key (stage_id) + references stage (id); + +alter table stage + add constraint fk_stage__festival + foreign key (festival_id) + references festival (id); + +alter table ticket + add constraint fk_ticket__stage + foreign key (stage_id) + references stage (id); + +alter table ticket_amount + add constraint fk_ticket_amount__ticket + foreign key (ticket_id) + references ticket (id); + +alter table ticket_entry_time + add constraint fk_ticket_entry_time__ticket + foreign key (ticket_id) + references ticket (id); + +alter table student + add constraint fk_student__member + foreign key (member_id) + references member (id); + +alter table student + add constraint fk_student__school + foreign key (school_id) + references school (id); + +alter table student_code + add constraint fk_student_code__member + foreign key (member_id) + references member (id); + +alter table student_code + add constraint fk_student_code__school + foreign key (school_id) + references school (id); diff --git a/backend/src/main/resources/festago-config b/backend/src/main/resources/festago-config index c62207dbc..9c3dddc6a 160000 --- a/backend/src/main/resources/festago-config +++ b/backend/src/main/resources/festago-config @@ -1 +1 @@ -Subproject commit c62207dbc32365bd0b0f6944a355f4f879073bc2 +Subproject commit 9c3dddc6a3c67db85357d819dfb3fc95e8a030aa diff --git a/backend/src/test/resources/application-test.yml b/backend/src/test/resources/application-test.yml index 30dbbd26a..44d7f0166 100644 --- a/backend/src/test/resources/application-test.yml +++ b/backend/src/test/resources/application-test.yml @@ -9,6 +9,8 @@ spring: hibernate: ddl-auto: create open-in-view: false + flyway: + enabled: false logging: file: