-
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: api-repo 모듈과 Jooq 설정을 추가합니다 (#22)
* remove: application-data-*.yml 삭제 * remove: Data 모듈 의존성 삭제 * move: *.sql 위치 변경 * feat: api-repo 모듈 추가 * feat: api-repo 모듈 jdbc, flyway 의존성 추가 * feat: data 모듈의 DataMigration 복사 및 실행 태스크 추가 * feat: api-repo 모듈 구성 설정 추가 * feat: DataSourceConfig 추가 * feat: FlywayConfig 추가 * feat: JOOQ 버전 추가 * feat: api-repo 모듈 jooq 의존성 추가 * feat: api-repo 모듈 jooqCodegen 테스크 정의 및 사전 조건 추가
- Loading branch information
1 parent
cc8b1ff
commit a7222fa
Showing
12 changed files
with
219 additions
and
27 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
tasks.getByName("bootJar") { | ||
enabled = false | ||
} | ||
|
||
tasks.getByName("jar") { | ||
enabled = true | ||
} | ||
|
||
plugins { | ||
/** jooq */ | ||
id("org.jooq.jooq-codegen-gradle") version DependencyVersion.JOOQ | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java { | ||
val mainDir = "src/main/kotlin" | ||
val jooqDir = "src/generated" | ||
srcDirs(mainDir, jooqDir) | ||
} | ||
} | ||
} | ||
|
||
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") | ||
|
||
/** jooq */ | ||
implementation("org.springframework.boot:spring-boot-starter-jooq") | ||
implementation("org.jooq:jooq:${DependencyVersion.JOOQ}") | ||
implementation("org.jooq:jooq-meta:${DependencyVersion.JOOQ}") | ||
implementation("org.jooq:jooq-codegen:${DependencyVersion.JOOQ}") | ||
jooqCodegen("org.jooq:jooq-meta-extensions:${DependencyVersion.JOOQ}") | ||
} | ||
|
||
/** copy data migration */ | ||
tasks.create("copyDataMigration") { | ||
doLast { | ||
val root = rootDir | ||
val flyWayResourceDir = "/db/migration/entity" | ||
val dataMigrationDir = "$root/data/$flyWayResourceDir" | ||
File(dataMigrationDir).walkTopDown().forEach { | ||
if (it.isFile) { | ||
it.copyTo( | ||
File("${project.projectDir}/src/main/resources$flyWayResourceDir/${it.name}"), | ||
true | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** copy data migration before compile kotlin */ | ||
tasks.getByName("compileKotlin") { | ||
dependsOn("copyDataMigration") | ||
} | ||
|
||
/** jooq codegen after copy data migration */ | ||
tasks.getByName("jooqCodegen") { | ||
dependsOn("copyDataMigration") | ||
} | ||
|
||
jooq { | ||
configuration { | ||
generator { | ||
database { | ||
name = "org.jooq.meta.extensions.ddl.DDLDatabase" | ||
properties { | ||
// Specify the location of your SQL script. | ||
// You may use ant-style file matching, e.g. /path/**/to/*.sql | ||
// | ||
// Where: | ||
// - ** matches any directory subtree | ||
// - * matches any number of characters in a directory / file name | ||
// - ? matches a single character in a directory / file name | ||
property { | ||
key = "scripts" | ||
value = "src/main/resources/db/migration/**/*.sql" | ||
} | ||
|
||
// The sort order of the scripts within a directory, where: | ||
// | ||
// - semantic: sorts versions, e.g. v-3.10.0 is after v-3.9.0 (default) | ||
// - alphanumeric: sorts strings, e.g. v-3.10.0 is before v-3.9.0 | ||
// - flyway: sorts files the same way as flyway does | ||
// - none: doesn't sort directory contents after fetching them from the directory | ||
property { | ||
key = "sort" | ||
value = "flyway" | ||
} | ||
|
||
// The default schema for unqualified objects: | ||
// | ||
// - public: all unqualified objects are located in the PUBLIC (upper case) schema | ||
// - none: all unqualified objects are located in the default schema (default) | ||
// | ||
// This configuration can be overridden with the schema mapping feature | ||
property { | ||
key = "unqualifiedSchema" | ||
value = "none" | ||
} | ||
|
||
// The default name case for unquoted objects: | ||
// | ||
// - as_is: unquoted object names are kept unquoted | ||
// - upper: unquoted object names are turned into upper case (most databases) | ||
// - lower: unquoted object names are turned into lower case (e.g. PostgreSQL) | ||
property { | ||
key = "defaultNameCase" | ||
value = "as_is" | ||
} | ||
} | ||
} | ||
|
||
generate { | ||
isDeprecated = false | ||
isRecords = true | ||
isImmutablePojos = true | ||
isFluentSetters = true | ||
isJavaTimeTypes = true | ||
} | ||
|
||
target { | ||
packageName = "jooq.jooq_dsl" | ||
directory = "src/generated" | ||
encoding = "UTF-8" | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api-repo/src/main/kotlin/com/few/api/repo/config/ApiRepoConfig.kt
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.api.repo.config | ||
|
||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = [ApiRepoConfig.BASE_PACKAGE]) | ||
class ApiRepoConfig { | ||
companion object { | ||
const val BASE_PACKAGE = "com.few.api.repo" | ||
const val SERVICE_NAME = "few" | ||
const val MODULE_NAME = "few-api-repo" | ||
const val BEAN_NAME_PREFIX = "fewApiRepo" | ||
const val PROPERTY_PREFIX = SERVICE_NAME + "." + MODULE_NAME | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
api-repo/src/main/kotlin/com/few/api/repo/datasource/DataSourceConfig.kt
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,30 @@ | ||
package com.few.api.repo.datasource | ||
|
||
import com.few.api.repo.config.ApiRepoConfig | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.jdbc.DataSourceBuilder | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager | ||
import org.springframework.transaction.PlatformTransactionManager | ||
import javax.sql.DataSource | ||
|
||
@Configuration | ||
class DataSourceConfig { | ||
|
||
companion object { | ||
const val API_DATASOURCE = ApiRepoConfig.BEAN_NAME_PREFIX + "DataSource" | ||
const val API_TX = ApiRepoConfig.BEAN_NAME_PREFIX + "TransactionManager" | ||
} | ||
|
||
@Bean(name = [API_DATASOURCE]) | ||
@ConfigurationProperties(prefix = "spring.datasource") | ||
fun apiDataSource(): DataSource { | ||
return DataSourceBuilder.create().build() | ||
} | ||
|
||
@Bean(name = [API_TX]) | ||
fun apiTransactionManager(): PlatformTransactionManager { | ||
return DataSourceTransactionManager(apiDataSource()) | ||
} | ||
} |
20 changes: 12 additions & 8 deletions
20
...otlin/com/few/data/flyway/FlywayConfig.kt → ...n/com/few/api/repo/flyway/FlywayConfig.kt
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
11 changes: 11 additions & 0 deletions
11
api-repo/src/main/resources/application-api-repo-local.yml
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,11 @@ | ||
spring: | ||
datasource: | ||
jdbcUrl: jdbc:mysql://localhost:13306/api?allowPublicKeyRetrieval=true&rewriteBatchedStatements=true | ||
username: root | ||
password: root | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
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,11 @@ | ||
spring: | ||
datasource: | ||
jdbcUrl: ${DB_HOSTNAME}/api?allowPublicKeyRetrieval=true&rewriteBatchedStatements=true | ||
username: ${DB_USERNAME} | ||
password: ${DB_PASSWORD} | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ rootProject.name = "few" | |
|
||
include("api") | ||
include("data") | ||
include("api-repo") |