【问题标题】:Liquibase module and a variable in Spring Boot ProjectSpring Boot 项目中的 Liquibase 模块和变量
【发布时间】:2020-10-13 19:32:56
【问题描述】:

我在我的项目中使用 liquibase,这是我的配置文件之一:

databaseChangeLog:
  - changeSet:
      id: 123
      author: m.rybalkin
      changes:
        - update:
            columns:
              - column:
                  name: code
                  value: '123'
            schemaName: prod
            tableName: config_bundle
            where: code='321'

这是我的“liquibase”模块的 build.gradle:

group 'com.project.test'
version '0.1.0'

buildscript {
    dependencies {
        classpath "org.liquibase:liquibase-gradle-plugin:${liqubasePluginVersion}"
        classpath "gradle.plugin.com.avast.gradle:gradle-docker-compose-plugin:${gradleDockerComposePluginVersion}"
    }
}

apply plugin: 'java'
apply plugin: 'org.liquibase.gradle'
apply plugin: 'com.avast.gradle.docker-compose'

dependencies {
    liquibaseRuntime "org.liquibase:liquibase-core:${liquibaseCoreVersion}"
    liquibaseRuntime "org.postgresql:postgresql:${postgresqlVersion}"
}

liquibase {
    activities {
        main {
            def file = new File("${projectDir}/liquibase.properties")
            if (file.exists()) {
                def props = new Properties()
                InputStream is = new FileInputStream(file)
                props.load(is)
                is.close()

                changeLogFile props['changeLogFile']
                outputFile 'liquibase/sql-migration-bundle.sql'
                url props['url']
                username props['username']
                password props['password']
            } else {
                println "Add ${projectDir}/liquibase.properties if you want use liquibase plugin"
            }
        }
        dockerPostgres {
            changeLogFile "${projectDir}/changelog/changelog-master.yml"
            url 'jdbc:postgresql://localhost:5555/test'
            username 'test'
            password 'test'
        }
        runList = 'main'
    }
}

task localUpdate(dependsOn: "composeUp") {
    doFirst {
        liquibase.setProperty("runList", "dockerPostgres")
    }
    finalizedBy update
}

task localDropAll(dependsOn: "composeUp") {
    doFirst {
        liquibase.setProperty("runList", "dockerPostgres")
    }
    finalizedBy dropAll
}

我的架构有两个不同的名称,一个“prod”用于生产,一个“test”用于测试。 是否可以在我的 application.yml 或 build.gradle 中设置一个变量,以便在我测试我的应用程序和部署它时更改名称?

附:我的 Spring 应用程序也有两个不同的配置文件 - “prod”和“test”

【问题讨论】:

    标签: spring-boot gradle liquibase


    【解决方案1】:

    你当然可以在 liquibase 运行时添加properties(可以从 gradle 传入,直接从命令行等)。

    例如,您可以在 CLI 上调用 liquibase: liquibase -Durl=更新

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      • 2018-11-29
      • 2019-05-24
      • 2015-10-10
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      相关资源
      最近更新 更多