-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: data 모듈 추가 * feat: data 모듈 spring starter 추가 - data-jdbc - mysql-connector-j * feat: FLYWAY 버전 변수 추가 * feat: data 모듈 flyway 의존성 추가 * feat: DataSource 빈 추가 * feat: TransactionManager 빈 추가 * feat: FlywayConfig 추가 * feat: data 모듈 구성 설정 추가 * feat: foo 테이블 추가 * remove: 데이터 소스 관련 코드 삭제
- Loading branch information
1 parent
f9aa4bd
commit e38e3d4
Showing
9 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tasks.getByName("bootJar") { | ||
enabled = false | ||
} | ||
|
||
tasks.getByName("jar") { | ||
enabled = true | ||
} | ||
|
||
dependencies { | ||
/** spring starter */ | ||
implementation("org.springframework.boot:spring-boot-starter-data-jdbc") | ||
implementation("com.mysql:mysql-connector-j") | ||
|
||
/** flyway */ | ||
implementation("org.flywaydb:flyway-core:${DependencyVersion.FLYWAY}") | ||
implementation("org.flywaydb:flyway-mysql") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.few.data.config | ||
|
||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = [DataConfig.BASE_PACKAGE]) | ||
class DataConfig { | ||
companion object { | ||
const val BASE_PACKAGE = "com.few.data" | ||
const val SERVICE_NAME = "few" | ||
const val MODULE_NAME = "few-data" | ||
const val BEAN_NAME_PREFIX = "fewData" | ||
const val PROPERTY_PREFIX = SERVICE_NAME + "." + MODULE_NAME | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.few.data.flyway | ||
|
||
import com.few.data.config.DataConfig | ||
import org.flywaydb.core.Flyway | ||
import org.flywaydb.core.api.configuration.FluentConfiguration | ||
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer | ||
import org.springframework.boot.autoconfigure.flyway.FlywayProperties | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Profile | ||
import java.util.function.Consumer | ||
import javax.sql.DataSource | ||
|
||
@Configuration | ||
class FlywayConfig { | ||
@Bean(name = [DataConfig.BEAN_NAME_PREFIX + "Flyway"]) | ||
fun flyway( | ||
configuration: org.flywaydb.core.api.configuration.Configuration? | ||
): Flyway { | ||
return Flyway(configuration) | ||
} | ||
|
||
@Profile("!new") | ||
@Bean(name = [DataConfig.BEAN_NAME_PREFIX + "FlywayValidateInitializer"]) | ||
fun flywayValidateInitializer( | ||
flyway: Flyway? | ||
): FlywayMigrationInitializer { | ||
return FlywayMigrationInitializer(flyway) { obj: Flyway -> obj.validate() } | ||
} | ||
|
||
@Bean(name = [DataConfig.BEAN_NAME_PREFIX + "FlywayMigrationInitializer"]) | ||
fun flywayMigrationInitializer( | ||
flyway: Flyway? | ||
): FlywayMigrationInitializer { | ||
return FlywayMigrationInitializer(flyway) { obj: Flyway -> obj.migrate() } | ||
} | ||
|
||
@Bean(name = [DataConfig.BEAN_NAME_PREFIX + "FlywayProperties"]) | ||
@ConfigurationProperties(prefix = "spring.flyway") | ||
fun flywayProperties(): FlywayProperties { | ||
return FlywayProperties() | ||
} | ||
|
||
@Bean(name = [DataConfig.BEAN_NAME_PREFIX + "FlywayConfiguration"]) | ||
fun configuration( | ||
dataSource: DataSource? | ||
): org.flywaydb.core.api.configuration.Configuration { | ||
val configuration = FluentConfiguration() | ||
configuration.dataSource(dataSource) | ||
flywayProperties().locations.forEach( | ||
Consumer { locations: String? -> | ||
configuration.locations( | ||
locations | ||
) | ||
} | ||
) | ||
return configuration | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
spring: | ||
flyway: | ||
locations: classpath:db/migration/entity | ||
sql-migration-suffixes: sql | ||
baseline-on-migrate: true | ||
baseline-version: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
spring: | ||
flyway: | ||
locations: classpath:db/migration/entity | ||
sql-migration-suffixes: sql | ||
baseline-on-migrate: true | ||
baseline-version: 0 |
7 changes: 7 additions & 0 deletions
7
data/src/main/resources/db/migration/entity/V1.00.0.0__init_foo_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE foo_tb | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
name VARCHAR(255) NOT NULL, | ||
deleted BIT NOT NULL, | ||
primary key (id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
rootProject.name = "few" | ||
|
||
include("api") | ||
include("data") |