Skip to content

Commit

Permalink
chore(dependencies): upgrade liquibase to 4.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kirangodishala committed Nov 16, 2023
1 parent 2fdb42e commit aa1e48d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static TestDatabase initDatabase(

Liquibase migrate;
try {
DatabaseChangeLog changeLog = new DatabaseChangeLog();
DatabaseChangeLog changeLog = new DatabaseChangeLog("db/changelog/");

changeLog.setChangeLogParameters(
new ChangeLogParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.netflix.spinnaker.kork.sql.config

import liquibase.GlobalConfiguration

/**
* Defines the configuration properties for connecting to a SQL database for schema migration purposes.
*
Expand All @@ -23,11 +25,14 @@ package com.netflix.spinnaker.kork.sql.config
* @param password The password to authenticate the [user]
* @param driver The JDBC driver name
* @param additionalChangeLogs A list of additional change log paths. This is useful for libraries and extensions.
* @param duplicateFileMode flag to handle if multiple files are found in the search path that have duplicate paths.
*/
data class SqlMigrationProperties(
var jdbcUrl: String? = null,
var user: String? = null,
var password: String? = null,
var driver: String? = null,
var additionalChangeLogs: List<String> = mutableListOf()
var additionalChangeLogs: List<String> = mutableListOf(),
var duplicateFileMode: GlobalConfiguration.DuplicateFileMode = GlobalConfiguration.DUPLICATE_FILE_MODE.defaultValue

)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.netflix.spinnaker.kork.sql.migration

import com.netflix.spinnaker.kork.sql.config.SqlMigrationProperties
import liquibase.GlobalConfiguration
import liquibase.Scope
import javax.sql.DataSource
import liquibase.integration.spring.SpringLiquibase
import org.springframework.jdbc.datasource.SingleConnectionDataSource
Expand All @@ -41,6 +43,13 @@ class SpringLiquibaseProxy(
init {
changeLog = "classpath:db/changelog-master.yml"
dataSource = createDataSource()
// Liquibase 4.21.0 onwards, there is a check in liquibase based on labelFilter value.
// This labelFilter is supposed to be used for running all those changeLogs having that label on them.
// But liquibase also runs all those which don't have any label.
// And by not assigning any value to that field either in SpringLiquibaseProxy object or SpringLiquibase object,
// liquibase is ignoring all those changeLogs defined through SpringLiquibase objects under
// SpringLiquibaseProxy's afterPropertiesSet() method below.
labelFilter = "spinnaker"
}

/**
Expand All @@ -52,18 +61,20 @@ class SpringLiquibaseProxy(
super.afterPropertiesSet()

// Then if anything else has been defined, do that afterwards
(sqlMigrationProperties.additionalChangeLogs + korkAdditionalChangelogs)
.map {
SpringLiquibase().apply {
changeLog = "classpath:$it"
dataSource = createDataSource()
resourceLoader = this@SpringLiquibaseProxy.resourceLoader
shouldRun = !sqlReadOnly
Scope.child(GlobalConfiguration.DUPLICATE_FILE_MODE.key, sqlMigrationProperties.duplicateFileMode) {
(sqlMigrationProperties.additionalChangeLogs + korkAdditionalChangelogs)
.map {
SpringLiquibase().apply {
changeLog = "classpath:$it"
dataSource = createDataSource()
resourceLoader = this@SpringLiquibaseProxy.resourceLoader
shouldRun = !sqlReadOnly
}
}
}
.forEach {
it.afterPropertiesSet()
}
.forEach {
it.afterPropertiesSet()
}
}
}

private fun createDataSource(): DataSource =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Import
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit.jupiter.SpringExtension
import strikt.api.expectThat
import strikt.assertions.isA
Expand All @@ -43,6 +44,7 @@ import strikt.assertions.isNotNull
"sql.enabled=true",
"sql.migration.jdbcUrl=jdbc:h2:mem:test",
"sql.migration.dialect=H2",
"sql.migration.duplicateFileMode=WARN",
"sql.connectionPool.jdbcUrl=jdbc:h2:mem:test",
"sql.connectionPool.dialect=H2"
]
Expand Down
3 changes: 3 additions & 0 deletions kork-sql/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ sql:
jdbcUrl: "jdbc:h2:mem:test"
user:
password:
duplicateFileMode: WARN
secondaryMigration:
jdbcUrl: "jdbc:h2:mem:test"
user:
password:
duplicateFileMode: WARN
---

spring:
Expand All @@ -52,3 +54,4 @@ sql:
jdbcUrl: "jdbc:h2:mem:test"
user:
password:
duplicateFileMode: WARN
2 changes: 1 addition & 1 deletion spinnaker-dependencies/spinnaker-dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ dependencies {
// containing `afterColumn` construct, with a validation error for postgresql. So pin with 3.10.3
api("org.liquibase:liquibase-core"){
version {
strictly "3.10.3"
strictly "4.24.0"
}
}
api("org.objenesis:objenesis:2.5.1")
Expand Down

0 comments on commit aa1e48d

Please sign in to comment.