|
|
|
@ -1,4 +1,8 @@ |
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper |
|
|
|
|
|
|
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory |
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
|
|
|
|
|
|
|
import java.io.FileInputStream |
|
|
|
|
|
|
|
|
|
|
|
plugins { |
|
|
|
plugins { |
|
|
|
id("org.springframework.boot") version "3.2.2" |
|
|
|
id("org.springframework.boot") version "3.2.2" |
|
|
|
@ -10,6 +14,12 @@ plugins { |
|
|
|
id("org.liquibase.gradle") version "2.2.1" |
|
|
|
id("org.liquibase.gradle") version "2.2.1" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buildscript { |
|
|
|
|
|
|
|
dependencies { |
|
|
|
|
|
|
|
classpath("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
group = "com.example" |
|
|
|
group = "com.example" |
|
|
|
version = "0.0.1-SNAPSHOT" |
|
|
|
version = "0.0.1-SNAPSHOT" |
|
|
|
|
|
|
|
|
|
|
|
@ -27,6 +37,7 @@ dependencies { |
|
|
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa") |
|
|
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa") |
|
|
|
implementation("org.springframework.boot:spring-boot-starter-validation") |
|
|
|
implementation("org.springframework.boot:spring-boot-starter-validation") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
liquibaseRuntime("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.1") |
|
|
|
liquibaseRuntime("org.liquibase:liquibase-core") |
|
|
|
liquibaseRuntime("org.liquibase:liquibase-core") |
|
|
|
liquibaseRuntime("org.liquibase.ext:liquibase-hibernate6:4.25.1") |
|
|
|
liquibaseRuntime("org.liquibase.ext:liquibase-hibernate6:4.25.1") |
|
|
|
liquibaseRuntime("info.picocli:picocli:4.6.3") |
|
|
|
liquibaseRuntime("info.picocli:picocli:4.6.3") |
|
|
|
@ -47,45 +58,51 @@ tasks.withType<Test> { |
|
|
|
useJUnitPlatform() |
|
|
|
useJUnitPlatform() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val profile: String by project |
|
|
|
|
|
|
|
val profileDbConf = getDbConf(profile) |
|
|
|
|
|
|
|
val referencedProfile: String? by project |
|
|
|
|
|
|
|
val referencedProfileDbConf = getDbConf(referencedProfile) |
|
|
|
|
|
|
|
val defaultChangeLogFile: String by project |
|
|
|
|
|
|
|
|
|
|
|
liquibase { |
|
|
|
liquibase { |
|
|
|
val profile = System.getProperty("profile") ?: "local" |
|
|
|
activities.register(profile) { |
|
|
|
|
|
|
|
this.arguments = (profileDbConf?.toMap() ?: emptyMap()) + |
|
|
|
// TODO: db.yaml objectMapper 로 읽어서 세팅? |
|
|
|
(referencedProfileDbConf?.toReferenceMap() ?: emptyMap()) + |
|
|
|
activities.register("local") { |
|
|
|
mapOf("changelogFile" to defaultChangeLogFile) |
|
|
|
this.arguments = mapOf( |
|
|
|
|
|
|
|
"url" to "jdbc:postgresql://localhost:15432/localdb", |
|
|
|
|
|
|
|
"username" to "flower", |
|
|
|
|
|
|
|
"password" to "flower" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
activities.register("dev") { |
|
|
|
|
|
|
|
this.arguments = mapOf( |
|
|
|
|
|
|
|
"url" to "jdbc:postgresql://flower-fragrance-stage.cluster-cbth1bnhfbdg.ap-northeast-2.rds.amazonaws.com:5432/devdb", |
|
|
|
|
|
|
|
"username" to "anypoint", |
|
|
|
|
|
|
|
"password" to "*emflaj*" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
runList = profile |
|
|
|
runList = profile |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun addArguments(name: String, args: Map<String, String>) { |
|
|
|
data class DbConf( |
|
|
|
val activity = liquibase.activities.getByName(name) |
|
|
|
val url: String? = null, |
|
|
|
activity.name = name |
|
|
|
val username: String? = null, |
|
|
|
val activityArgs = activity.arguments as Map<*, *> |
|
|
|
val password: String? = null |
|
|
|
val newArgs = mutableMapOf<String, String>() |
|
|
|
) { |
|
|
|
newArgs.putAll(activityArgs.map { it.key as String to it.value as String }) |
|
|
|
fun toMap(): Map<String, String?> = mapOf( |
|
|
|
newArgs.putAll(args) |
|
|
|
"url" to url, |
|
|
|
|
|
|
|
"username" to username, |
|
|
|
newArgs.forEach { |
|
|
|
"password" to password |
|
|
|
println("arguments[\"${it.key}\"]=\"${it.value}\"") |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun toReferenceMap(): Map<String, String?> = mapOf( |
|
|
|
|
|
|
|
"reference-url" to url, |
|
|
|
|
|
|
|
"reference-username" to username, |
|
|
|
|
|
|
|
"reference-password" to password |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
activity.arguments = newArgs |
|
|
|
fun getDbConf(profile: String?): DbConf? = profile?.let { |
|
|
|
|
|
|
|
ObjectMapper(YAMLFactory()) |
|
|
|
|
|
|
|
.readValue( |
|
|
|
|
|
|
|
FileInputStream(File(projectDir, "db.yaml")), |
|
|
|
|
|
|
|
object : TypeReference<Map<String, DbConf>>() {} |
|
|
|
|
|
|
|
)[profile] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tasks.getByName("generateChangelog").doFirst { |
|
|
|
tasks.getByName("generateChangelog").doFirst { |
|
|
|
val changeLogFile = "src/main/resources/liquibase/postgres/changelog/generated.yaml" |
|
|
|
delete(defaultChangeLogFile) |
|
|
|
delete(changeLogFile) |
|
|
|
} |
|
|
|
val name = System.getProperty("name") ?: "local" |
|
|
|
|
|
|
|
addArguments(name, mapOf("changeLogFile" to changeLogFile)) |
|
|
|
tasks.getByName("diffChangelog").doFirst { |
|
|
|
|
|
|
|
delete(defaultChangeLogFile) |
|
|
|
} |
|
|
|
} |