diff --git a/README.md b/README.md index 620c48c..2945ebd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ### feature 브랜치 생성 - gitflow 방식에 의해 develop 브랜치로부터 feature 브랜치 생성 -- feature 브랜치 명명 규칙: `feature/(postgres | assign-redshift | device-redshift)-v[-]` +- feature 브랜치 명명 규칙: `feature/postgres-v[-]` - `v` 는 소문자 - changelog 버젼 충동을 방지하기 위함 - 명명 규칙에 의거하여 리모트 레파지토리에 먼저 올린 브랜치가 버젼 선점에 대한 우선권을 갖습니다. @@ -24,7 +24,7 @@ ### changelog 파일 생성하거나 generate 된 파일 변경 -- 위치: `src/main/resources/(postgres | assign-redshift | device-redshift)/changelog` +- 위치: `src/main/resources/postgres/changelog` - 파일 형식: `v[.]__(ddl | dml)__.yaml` - `v` 는 소문자 - `_` 가 2개임 @@ -47,7 +47,7 @@ ### apm-stage 에 반영 ```shell -./gradlew update --db (postgres | assign-redshift | device-redshift) --profile apm-dev +./gradlew update --profile apm-dev ``` ### 운영 반영 @@ -55,7 +55,7 @@ 1. release/hotfix 브랜치 생성 1. 반영 ```shell - ./gradlew update --db (postgres | assign-redshift | device-redshift) --profile (skb-prod | uplus-prod | flower-prod) + ./gradlew update --profile (skb-prod | uplus-prod | flower-prod) ``` 1. changelog 파일에 태그 달기(운영 작업 후 필수) * major version: 테이블을 추가하거나 삭제한 경우 major version 을 올린다. diff --git a/build.gradle.kts b/build.gradle.kts index 9ff4b9a..fce434e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,18 +29,13 @@ dependencies { liquibaseRuntime("org.liquibase:liquibase-core") liquibaseRuntime("org.liquibase.ext:liquibase-hibernate6:4.25.1") + liquibaseRuntime("info.picocli:picocli:4.6.3") liquibaseRuntime("com.h2database:h2") liquibaseRuntime("org.postgresql:postgresql") testImplementation("org.springframework.boot:spring-boot-starter-test") } -liquibase { - activities.register("postgres") { - this.arguments = mapOf("changeLogFile" to "src/main/resources/postgres/dev.yaml") - } -} - tasks.withType { kotlinOptions { freeCompilerArgs += "-Xjsr305=strict" @@ -51,3 +46,46 @@ tasks.withType { tasks.withType { useJUnitPlatform() } + +liquibase { + val profile = System.getProperty("profile") ?: "local" + +// TODO: db.yaml objectMapper 로 읽어서 세팅? + activities.register("local") { + 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 +} + +fun addArguments(name: String, args: Map) { + val activity = liquibase.activities.getByName(name) + activity.name = name + val activityArgs = activity.arguments as Map<*, *> + val newArgs = mutableMapOf() + newArgs.putAll(activityArgs.map { it.key as String to it.value as String }) + newArgs.putAll(args) + + newArgs.forEach { + println("arguments[\"${it.key}\"]=\"${it.value}\"") + } + + activity.arguments = newArgs +} + +tasks.getByName("generateChangelog").doFirst { + val changeLogFile = "src/main/resources/liquibase/postgres/changelog/generated.yaml" + delete(changeLogFile) + val name = System.getProperty("name") ?: "local" + addArguments(name, mapOf("changeLogFile" to changeLogFile)) +} diff --git a/src/main/resources/postgres/dev.yaml b/src/main/resources/liquibase/postgres/dev.yaml similarity index 100% rename from src/main/resources/postgres/dev.yaml rename to src/main/resources/liquibase/postgres/dev.yaml diff --git a/src/main/resources/postgres/prod.yaml b/src/main/resources/liquibase/postgres/prod.yaml similarity index 100% rename from src/main/resources/postgres/prod.yaml rename to src/main/resources/liquibase/postgres/prod.yaml diff --git a/src/main/resources/postgres/stage.yaml b/src/main/resources/postgres/stage.yaml deleted file mode 100644 index e69de29..0000000