Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ dependencies {

/* DATABASE */
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.flywaydb:flyway-mysql'
implementation 'org.flywaydb:flyway-core'

/* MONITORING */
implementation 'io.micrometer:micrometer-registry-prometheus'
Expand Down
36 changes: 23 additions & 13 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ spring:
username: ${DB_USERNAME}
password: ${DB_PASSWORD}

flyway:
enabled: false

data:
redis:
host: ${REDIS_HOST}
Expand Down Expand Up @@ -78,6 +81,9 @@ spring:
activate:
on-profile: dev

flyway:
enabled: false

management:
server:
port: ${ACTUATOR_PORT}
Expand All @@ -95,19 +101,23 @@ spring:
activate:
on-profile: prod

# TODO: Flyway 추가와 함께 설정이 필요한 항목들
# sql:
# init:
# mode: never
#
# jpa:
# hibernate:
# ddl-auto: none
#
# properties:
# hibernate:
# show_sql: false
# format_sql: false
flyway:
enabled: true
locations: classpath:db/migration

sql:
init:
mode: never

jpa:
defer-datasource-initialization: false
hibernate:
ddl-auto: none

properties:
hibernate:
show_sql: false
format_sql: false

management:
server:
Expand Down
77 changes: 77 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,77 @@
CREATE TABLE admin (
id BIGINT NOT NULL AUTO_INCREMENT,
username VARCHAR(20) NOT NULL,
password VARCHAR(20) NOT NULL,
last_login DATETIME(6) NOT NULL,
created_at DATETIME(6),
updated_at DATETIME(6),
PRIMARY KEY (id)
);

CREATE TABLE `user` (
id BIGINT NOT NULL AUTO_INCREMENT,
nickname varchar(10),
provider varchar(10) NOT NULL,
provider_id varchar(20) NOT NULL,
last_login DATETIME(6) NOT NULL,
created_at DATETIME(6),
updated_at DATETIME(6),
PRIMARY KEY (id)
);

CREATE TABLE stat (
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT NOT NULL,
total_games BIGINT NOT NULL,
winning_games BIGINT NOT NULL,
score BIGINT NOT NULL,
created_at DATETIME(6),
updated_at DATETIME(6),
PRIMARY KEY (id)
);

CREATE TABLE quiz (
id BIGINT NOT NULL AUTO_INCREMENT,
title VARCHAR(40) NOT NULL,
quiz_type VARCHAR(10) NOT NULL,
creator_id BIGINT,
description VARCHAR(60) NOT NULL,
thumbnail_url VARCHAR(255) NOT NULL,
created_at DATETIME(6),
updated_at DATETIME(6),
PRIMARY KEY (id)
);

CREATE TABLE question (
id BIGINT NOT NULL AUTO_INCREMENT,
quiz_id BIGINT NOT NULL,
answer VARCHAR(40) NOT NULL,
created_at DATETIME(6),
updated_at DATETIME(6),
PRIMARY KEY (id)
);

CREATE TABLE text_question (
id BIGINT NOT NULL AUTO_INCREMENT,
question_id BIGINT NOT NULL,
content varchar(40) NOT NULL,
PRIMARY KEY (id)
);

ALTER TABLE stat ADD CONSTRAINT UK_stat__user_id UNIQUE (user_id);

ALTER TABLE text_question ADD CONSTRAINT UK_text_question__question_id UNIQUE (question_id);

ALTER TABLE `user` ADD CONSTRAINT UK_user__nickname unique (nickname);

ALTER TABLE question ADD CONSTRAINT FK_question__quiz_id
FOREIGN KEY (quiz_id) REFERENCES quiz (id);

ALTER TABLE quiz ADD CONSTRAINT FK_quiz__creator_id
FOREIGN KEY (creator_id) REFERENCES `user` (id) ON DELETE SET NULL;

ALTER TABLE stat ADD CONSTRAINT FK_stat__user_id
FOREIGN KEY (user_id) REFERENCES `user` (id);

ALTER TABLE text_question ADD CONSTRAINT FK_test_question__question_id
FOREIGN KEY (question_id) REFERENCES question (id);
3 changes: 3 additions & 0 deletions backend/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ spring:
init:
mode: never

flyway:
enabled: false

security:
oauth2:
client:
Expand Down