Maksym Rybalkin
Maksym Rybalkin

Reputation: 545

Liquibase module and a variable in Spring Boot Project

I use liquibase in my project, and here is one of my config files:

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

Here is my build.gradle of the "liquibase" module:

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
}

I have two different names of my schema, a "prod" for production and a "test" for tests. Is it possible to set a variable in my application.yml or build.gradle for changing the name when I'm testing my app and when I'm deploying it?

P.S. I also have two different profiles of my Spring app - "prod" and "test"

Upvotes: 0

Views: 807

Answers (1)

ronak
ronak

Reputation: 646

You certainly can add properties at runtime of liquibase (which can be passed in from gradle, directly from commandline, etc).

So you can for example call liquibase on the CLI: liquibase -Durl= update

Upvotes: 2

Related Questions