mirror of
https://github.com/corda/corda.git
synced 2025-01-28 23:24:29 +00:00
Fix null migration resource (#210)
throw exception when migration not set for MappedSchema
This commit is contained in:
parent
3ab1a06db6
commit
dd59b06c62
@ -38,15 +38,16 @@ interface QueryableState : ContractState {
|
||||
* @param mappedTypes The JPA entity classes that the ORM layer needs to be configure with for this schema.
|
||||
*/
|
||||
open class MappedSchema(schemaFamily: Class<*>,
|
||||
val version: Int,
|
||||
val mappedTypes: Iterable<Class<*>>) {
|
||||
val version: Int,
|
||||
val mappedTypes: Iterable<Class<*>>) {
|
||||
val name: String = schemaFamily.name
|
||||
|
||||
/**
|
||||
* Points to a classpath resource containing the database changes for the [mappedTypes]
|
||||
*/
|
||||
protected open val migrationResource: String? = null
|
||||
internal fun getMigrationResource(): String = migrationResource!!
|
||||
|
||||
internal fun getMigrationResource(): String = migrationResource ?: throw IllegalStateException("Migration resource not set for schema $this")
|
||||
|
||||
override fun toString(): String = "${this.javaClass.simpleName}(name=$name, version=$version)"
|
||||
}
|
||||
|
@ -28,18 +28,18 @@ class SchemaMigration(val schemas: Set<MappedSchema>, val dataSource: DataSource
|
||||
|
||||
dataSource.connection.use { connection ->
|
||||
|
||||
//collect all changelog file referenced in the included schemas
|
||||
val changelogList = schemas.map { mappedSchema ->
|
||||
getMigrationResource(mappedSchema).let {
|
||||
"${MIGRATION_PREFIX}/${it}.xml"
|
||||
}
|
||||
}
|
||||
|
||||
//create a resourse accessor that aggregates the changelogs included in the schemas into one dynamic stream
|
||||
val customResourceAccessor = object : ClassLoaderResourceAccessor() {
|
||||
override fun getResourcesAsStream(path: String): Set<InputStream> {
|
||||
|
||||
if (path == dynamicInclude) {
|
||||
//collect all changelog file referenced in the included schemas
|
||||
val changelogList = schemas.map { mappedSchema ->
|
||||
getMigrationResource(mappedSchema).let {
|
||||
"${MIGRATION_PREFIX}/${it}.xml"
|
||||
}
|
||||
}
|
||||
|
||||
//create a map in liquibase format including all migration files
|
||||
val includeAllFiles = mapOf("databaseChangeLog" to changelogList.map { file -> mapOf("include" to mapOf("file" to file)) })
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user