Skip to content

Commit

Permalink
[BE] feat: Flyway ์ ์šฉ (#246) (#334)
Browse files Browse the repository at this point in the history
* chore: Flyway ์˜์กด์„ฑ ์ถ”๊ฐ€

* chore: Flyway ์„ค์ • ์ถ”๊ฐ€

* chore: ์„œ๋ธŒ๋ชจ๋“ˆ ์—…๋ฐ์ดํŠธ

* chore: h2 ์„ค์ • ์ œ๊ฑฐ

* feat: ์ตœ์‹  ๋ธŒ๋žœ์น˜ ๋ฐ˜์˜

* feat: Admin ํ…Œ์ด๋ธ” ์ถ”๊ฐ€

* feat: ์ตœ์‹  ์—”ํ‹ฐํ‹ฐ DDL ์„ค์ •

* feat: submodule ์—…๋ฐ์ดํŠธ
  • Loading branch information
seokjin8678 authored and BGuga committed Oct 17, 2023
1 parent 3d81e44 commit 12a02dd
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 11 deletions.
4 changes: 4 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
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" ]
3 changes: 2 additions & 1 deletion backend/src/main/java/com/festago/auth/domain/Admin.java
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/com/festago/domain/School.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import jakarta.validation.constraints.Size;

@Entity
public class School {
public class School extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/com/festago/domain/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import jakarta.validation.constraints.Size;

@Entity
public class Student {
public class Student extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
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
195 changes: 195 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,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);
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:
file:
Expand Down

0 comments on commit 12a02dd

Please sign in to comment.