mirror of
https://github.com/corda/corda.git
synced 2024-12-23 14:52:29 +00:00
CORDA-2651 Remove null values from changelog list (#5022)
* CORDA-2651 Check if resources are in classpath before passing them to Liquibase * CORDA-2651 Add missing stop * CORDA-2651 Change exception type. Improve exception log message. * CORDA-2651 Add null check when getting resources from class loader * CORDA-2651 Do not include null values in the changelog list
This commit is contained in:
parent
87fe7b4d88
commit
864a355e63
@ -13,7 +13,6 @@ import net.corda.nodeapi.internal.MigrationHelpers.getMigrationResource
|
||||
import net.corda.core.schemas.MappedSchema
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.nodeapi.internal.cordapp.CordappLoader
|
||||
import sun.security.x509.X500Name
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Path
|
||||
@ -99,7 +98,7 @@ class SchemaMigration(
|
||||
|
||||
// Collect all changelog file referenced in the included schemas.
|
||||
// For backward compatibility reasons, when failOnMigrationMissing=false, we don't manage CorDapps via Liquibase but use the hibernate hbm2ddl=update.
|
||||
val changelogList = schemas.map { mappedSchema ->
|
||||
val changelogList = schemas.mapNotNull { mappedSchema ->
|
||||
val resource = getMigrationResource(mappedSchema, classLoader)
|
||||
when {
|
||||
resource != null -> resource
|
||||
@ -115,6 +114,7 @@ class SchemaMigration(
|
||||
}
|
||||
System.setProperty(NODE_X500_NAME, ourName.toString())
|
||||
val customResourceAccessor = CustomResourceAccessor(dynamicInclude, changelogList, classLoader)
|
||||
checkResourcesInClassPath(changelogList)
|
||||
|
||||
// current version of Liquibase appears to be non-threadsafe
|
||||
// this is apparent when multiple in-process nodes are all running migrations simultaneously
|
||||
@ -209,6 +209,7 @@ class SchemaMigration(
|
||||
|
||||
if (preV4Baseline.isNotEmpty()) {
|
||||
val dynamicInclude = "master.changelog.json" // Virtual file name of the changelog that includes all schemas.
|
||||
checkResourcesInClassPath(preV4Baseline)
|
||||
dataSource.connection.use { connection ->
|
||||
val customResourceAccessor = CustomResourceAccessor(dynamicInclude, preV4Baseline, classLoader)
|
||||
val liquibase = Liquibase(dynamicInclude, customResourceAccessor, getLiquibaseDatabase(JdbcConnection(connection)))
|
||||
@ -217,6 +218,14 @@ class SchemaMigration(
|
||||
}
|
||||
return isExistingDBWithoutLiquibase || isFinanceAppWithLiquibaseNotMigrated
|
||||
}
|
||||
|
||||
private fun checkResourcesInClassPath(resources: List<String?>) {
|
||||
for (resource in resources) {
|
||||
if (resource != null && classLoader.getResource(resource) == null) {
|
||||
throw DatabaseMigrationException("Could not find Liquibase database migration script $resource. Please ensure the jar file containing it is deployed in the cordapps directory.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class DatabaseMigrationException(message: String) : IllegalArgumentException(message) {
|
||||
|
Loading…
Reference in New Issue
Block a user