[#28] feat: flyway migration용 gradle module 추가
- db 모듈 추가 - dongne-service-api 모듈에 적용되어 있던 flyway migration 내용 삭제
This commit is contained in:
38
README.md
38
README.md
@@ -9,27 +9,57 @@
|
||||
- java 17
|
||||
- kotlin 1.6.21
|
||||
- Spring Boot 2.7.0
|
||||
- MySQL
|
||||
- MySQL 8.0.21
|
||||
|
||||
<br>
|
||||
|
||||
## Multi Modules
|
||||
## :pushpin: Multi Modules
|
||||
- `dongne-account-api`
|
||||
- 회원가입, 인증 관련 내용
|
||||
- `dongne-service-api`
|
||||
- 카페 관련 도메인 내용(추후 주문, 결제 적용 계획)
|
||||
- `dongne-common`
|
||||
- entity, repository, error, security(jwt util) 등 관리하는 공통모듈
|
||||
- `db`
|
||||
- flyway migration(gradle) 적용 모듈
|
||||
|
||||
<br>
|
||||
|
||||
## Run Application
|
||||
## :pushpin: Run Application
|
||||
|
||||
### 로컬 환경 내 로컬 DB 따로 구성
|
||||
- local에 DB(MySQL)용 docker container run
|
||||
- application은 IDE에서 실행 (default profile: `local`)
|
||||
```bash
|
||||
$ docker run --name beanie-test-db -e MYSQL_ROOT_PASSWORD=beaniejoy -d -p 3306:3306 mysql:5.7.34
|
||||
$ docker run --name beanie-test-db -e MYSQL_ROOT_PASSWORD=beaniejoy -d -p 3306:3306 mysql:8.0.21
|
||||
```
|
||||
|
||||
### DB Migration (flyway)
|
||||
- **Info**
|
||||
Prints the details and status information about all the migrations
|
||||
```bash
|
||||
$ ./gradlew :db:flywayInfo
|
||||
```
|
||||
- **Validate**
|
||||
Validates the applied migrations against the available ones
|
||||
DB에 적용된 migration과 local에 적용된 migration 정보 일치 여부 체크
|
||||
```bash
|
||||
$ ./gradlew :db:flywayValidate
|
||||
```
|
||||
- **Migrate**
|
||||
Migrates the schema to the latest version
|
||||
migration 설정 내용들 반영
|
||||
```bash
|
||||
$ ./gradlew :db:flywayMigrate
|
||||
```
|
||||
- **Clean**
|
||||
Drops all objects (tables, views, procedures, triggers, …) in the configured schemas
|
||||
(prodution 단계에서는 절대 사용 X)
|
||||
```bash
|
||||
$ ./gradlew :db:flywayClean -i
|
||||
```
|
||||
|
||||
|
||||
### docker compose 실행(수정 작업 진행중)
|
||||
- docker compose를 이용한 nginx, DB(MySQL), application 한꺼번에 실행하는 경우
|
||||
```bash
|
||||
|
||||
@@ -27,7 +27,7 @@ subprojects {
|
||||
plugin(Plugins.Spring.dependencyManagement)
|
||||
plugin(Plugins.Spring.boot)
|
||||
|
||||
plugin(Plugins.Kotlin.kotlin)
|
||||
plugin(Plugins.Kotlin.KOTLIN)
|
||||
plugin(Plugins.Kotlin.kotlinSpring)
|
||||
plugin(Plugins.Kotlin.kotlinJpa)
|
||||
}
|
||||
@@ -50,7 +50,6 @@ subprojects {
|
||||
// DB
|
||||
runtimeOnly("mysql:mysql-connector-java") // MySQL
|
||||
runtimeOnly("com.h2database:h2") // H2
|
||||
implementation("org.flywaydb:flyway-core:${Version.Deps.flywayCore}") // flyway
|
||||
|
||||
// JWT
|
||||
implementation("io.jsonwebtoken:jjwt-api:${Version.Deps.Jwt}")
|
||||
@@ -58,7 +57,7 @@ subprojects {
|
||||
runtimeOnly("io.jsonwebtoken:jjwt-jackson:${Version.Deps.Jwt}")
|
||||
|
||||
// Logging
|
||||
implementation("io.github.microutils:kotlin-logging:${Version.Deps.kotlinLogging}")
|
||||
implementation("io.github.microutils:kotlin-logging:${Version.Deps.KOTLIN_LOGGING}")
|
||||
|
||||
// Test
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
@@ -7,7 +7,7 @@ object Plugins {
|
||||
}
|
||||
|
||||
object Kotlin {
|
||||
const val kotlin = "kotlin"
|
||||
const val KOTLIN = "kotlin"
|
||||
const val kotlinSpring = "kotlin-spring"
|
||||
const val kotlinJpa = "kotlin-jpa"
|
||||
|
||||
@@ -15,4 +15,8 @@ object Plugins {
|
||||
const val pluginSpring = "plugin.spring"
|
||||
const val pluginJpa = "plugin.jpa"
|
||||
}
|
||||
|
||||
object FlywayDB {
|
||||
const val FLYWAY = "org.flywaydb.flyway"
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,11 @@ object Version {
|
||||
}
|
||||
|
||||
object Deps {
|
||||
const val flywayCore = "7.15.0"
|
||||
const val kotlinLogging = "2.1.21"
|
||||
const val KOTLIN_LOGGING = "3.0.4"
|
||||
const val Jwt = "0.11.5"
|
||||
}
|
||||
|
||||
object FlywayDB {
|
||||
const val FLYWAY_CORE = "9.8.1"
|
||||
}
|
||||
}
|
||||
26
db/build.gradle.kts
Normal file
26
db/build.gradle.kts
Normal file
@@ -0,0 +1,26 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.flywaydb:flyway-mysql:${Version.FlywayDB.FLYWAY_CORE}")
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id(Plugins.FlywayDB.FLYWAY).version(Version.FlywayDB.FLYWAY_CORE)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.flywaydb:flyway-core:${Version.FlywayDB.FLYWAY_CORE}") // flyway
|
||||
}
|
||||
|
||||
flyway {
|
||||
baselineDescription = "Start Flyway Migration!"
|
||||
baselineOnMigrate = true
|
||||
baselineVersion = "000"
|
||||
locations = arrayOf("filesystem:./migration", "filesystem:./seed")
|
||||
configFiles = arrayOf("conf/flyway.conf")
|
||||
cleanDisabled = false // activate flywayClean
|
||||
ignoreMigrationPatterns = arrayOf("*:pending") // ignore validating pending(대기) state
|
||||
}
|
||||
4
db/conf/flyway.conf
Normal file
4
db/conf/flyway.conf
Normal file
@@ -0,0 +1,4 @@
|
||||
flyway.url=jdbc:mysql://localhost:3306/dongne?autoreconnect=true&characterEncoding=utf8&serverTimezone=Asia/Seoul
|
||||
flyway.user=root
|
||||
flyway.password=beaniejoy
|
||||
flyway.driver=com.mysql.cj.jdbc.Driver
|
||||
15
db/migration/V001__Delete_all.sql
Normal file
15
db/migration/V001__Delete_all.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- suppress warning message about unknown table
|
||||
SET sql_notes = 0;
|
||||
|
||||
DROP TABLE IF EXISTS `option_detail`;
|
||||
DROP TABLE IF EXISTS `menu_option`;
|
||||
DROP TABLE IF EXISTS `cafe_image`;
|
||||
DROP TABLE IF EXISTS `cafe_menu`;
|
||||
DROP TABLE IF EXISTS `cafe`;
|
||||
|
||||
DROP PROCEDURE IF EXISTS insertCafeImages;
|
||||
DROP PROCEDURE IF EXISTS insertCafeMenus;
|
||||
DROP PROCEDURE IF EXISTS insertMenuOptions;
|
||||
DROP PROCEDURE IF EXISTS insertOptionDetails;
|
||||
|
||||
-- SET sql_notes = 0;
|
||||
@@ -5,7 +5,7 @@ CREATE TABLE `member` (
|
||||
`address` varchar(100) NOT NULL COMMENT '회원 주소',
|
||||
`phone_number` varchar(11) NOT NULL COMMENT '회원 전화번호',
|
||||
`role_type` varchar(20) COMMENT '회원 권한',
|
||||
`activated` tinyint(1) NOT NULL COMMENT '계정 활성화 여부',
|
||||
`activated` tinyint NOT NULL COMMENT '계정 활성화 여부',
|
||||
`created_at` datetime NOT NULL COMMENT '회원 등록날짜',
|
||||
`created_by` varchar(20) NOT NULL COMMENT '회원 등록자',
|
||||
`updated_at` datetime NULL COMMENT '회원 변경날짜',
|
||||
@@ -1,5 +1,3 @@
|
||||
DROP PROCEDURE IF EXISTS insertCafeImages;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE insertCafeImages()
|
||||
BEGIN
|
||||
@@ -1,5 +1,3 @@
|
||||
DROP PROCEDURE IF EXISTS insertCafeMenus;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE insertCafeMenus()
|
||||
BEGIN
|
||||
@@ -1,5 +1,3 @@
|
||||
DROP PROCEDURE IF EXISTS insertMenuOptions;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE insertMenuOptions()
|
||||
BEGIN
|
||||
@@ -1,5 +1,3 @@
|
||||
DROP PROCEDURE IF EXISTS insertOptionDetails;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE insertOptionDetails()
|
||||
BEGIN
|
||||
@@ -11,10 +11,6 @@ spring:
|
||||
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
||||
format_sql: true
|
||||
show-sql: false
|
||||
flyway:
|
||||
baseline-on-migrate: true
|
||||
baseline-version: "000"
|
||||
locations: classpath:db/migration,classpath:db/seed
|
||||
devtools:
|
||||
livereload:
|
||||
enabled: false # no use devtools' LiveReload Server
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
DROP TABLE IF EXISTS `option_detail`;
|
||||
DROP TABLE IF EXISTS `menu_option`;
|
||||
DROP TABLE IF EXISTS `cafe_image`;
|
||||
DROP TABLE IF EXISTS `cafe_menu`;
|
||||
DROP TABLE IF EXISTS `cafe`;
|
||||
@@ -2,3 +2,4 @@ rootProject.name = "dongne-cafe-api"
|
||||
include("dongne-common")
|
||||
include("dongne-service-api")
|
||||
include("dongne-account-api")
|
||||
include("db")
|
||||
|
||||
Reference in New Issue
Block a user