Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: Flyway 적용 (#246) #334

Merged
merged 12 commits into from
Sep 11, 2023
4 changes: 4 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ dependencies {

// Logback Slack Alarm
implementation "com.github.maricn:logback-slack-appender:1.4.0"

// Flyway
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'
}

tasks.named('test') {
Expand Down
15 changes: 15 additions & 0 deletions backend/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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" ]
Comment on lines +1 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

내마음이 도커도커

Comment on lines +1 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h2 의 문법 문제와 dev, prod 환경과 최대한 비슷한 환경을 local 에서 구성해 보는 것도 큰 장점인 것 같네요!!

16 changes: 9 additions & 7 deletions backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
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 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;

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);
2 changes: 1 addition & 1 deletion backend/src/main/resources/festago-config
2 changes: 2 additions & 0 deletions backend/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ spring:
hibernate:
ddl-auto: create
open-in-view: false
flyway:
enabled: false

logging:
level:
Expand Down