ENT-1517: Move MigrationHelpers object into internal package. (#457)

This commit is contained in:
Chris Rankin 2018-02-12 23:20:46 +00:00 committed by GitHub
parent ef45900fda
commit c3f08ecf5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 12 deletions

View File

@ -1,3 +1,5 @@
package net.corda.core.internal
import com.google.common.base.CaseFormat
import net.corda.core.schemas.MappedSchema
@ -13,12 +15,12 @@ object MigrationHelpers {
if (declaredMigration == null) {
// try to apply the naming convention and find the migration file in the classpath
val resource = migrationResourceNameForSchema(schema)
return possibleMigrationExtensions.map { "${resource}${it}" }.firstOrNull {
return possibleMigrationExtensions.map { "$resource$it" }.firstOrNull {
classLoader.getResource(it) != null
}
}
return "${MIGRATION_PREFIX}/${declaredMigration}.${DEFAULT_MIGRATION_EXTENSION}"
return "$MIGRATION_PREFIX/$declaredMigration.$DEFAULT_MIGRATION_EXTENSION"
}
// SchemaName will be transformed from camel case to lower_hyphen
@ -26,6 +28,6 @@ object MigrationHelpers {
fun migrationResourceNameForSchema(schema: MappedSchema): String {
val name: String = schema::class.simpleName!!
val fileName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name)
return "${MIGRATION_PREFIX}/${fileName}.${CHANGELOG_NAME}"
return "$MIGRATION_PREFIX/$fileName.$CHANGELOG_NAME"
}
}

View File

@ -1,7 +1,7 @@
package net.corda.node.services.persistence
import MigrationHelpers.migrationResourceNameForSchema
import net.corda.core.identity.AbstractParty
import net.corda.core.internal.MigrationHelpers.migrationResourceNameForSchema
import net.corda.core.internal.objectOrNewInstance
import net.corda.core.schemas.MappedSchema
import net.corda.nodeapi.internal.persistence.CordaPersistence
@ -53,7 +53,7 @@ class MigrationExporter(val parent: Path, val datasourceProperties: Properties,
createNewFile()
appendText(LIQUIBASE_HEADER)
appendText("\n\n")
appendText("--changeset ${CORDA_USER}:initial_schema_for_${mappedSchema::class.simpleName!!}")
appendText("--changeset $CORDA_USER:initial_schema_for_${mappedSchema::class.simpleName!!}")
appendText("\n")
}

View File

@ -1,6 +1,5 @@
package net.corda.nodeapi.internal.persistence
import MigrationHelpers.getMigrationResource
import com.fasterxml.jackson.databind.ObjectMapper
import liquibase.Contexts
import liquibase.LabelExpression
@ -11,6 +10,7 @@ import liquibase.database.core.MSSQLDatabase
import liquibase.database.jvm.JdbcConnection
import liquibase.lockservice.LockServiceFactory
import liquibase.resource.ClassLoaderResourceAccessor
import net.corda.core.internal.MigrationHelpers.getMigrationResource
import net.corda.core.schemas.MappedSchema
import net.corda.core.utilities.contextLogger
import java.io.*
@ -31,7 +31,7 @@ class SchemaMigration(
* Main entry point to the schema migration.
* Called during node startup.
*/
fun nodeStartup(): Unit {
fun nodeStartup() {
when {
databaseConfig.runMigration -> runMigration()
failOnMigrationMissing -> checkState()
@ -56,7 +56,7 @@ class SchemaMigration(
/**
* can be used from an external tool to release the lock in case something went terribly wrong
*/
fun forceReleaseMigrationLock(): Unit {
fun forceReleaseMigrationLock() {
dataSource.connection.use { connection ->
LockServiceFactory.getInstance().getLockService(getLiquibaseDatabase(JdbcConnection(connection))).forceReleaseLock()
}

View File

@ -2,7 +2,6 @@
package com.r3.corda.dbmigration
import MigrationHelpers
import com.typesafe.config.ConfigFactory
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
@ -10,6 +9,7 @@ import joptsimple.OptionException
import joptsimple.OptionParser
import joptsimple.OptionSet
import joptsimple.util.EnumConverter
import net.corda.core.internal.MigrationHelpers
import net.corda.core.internal.copyTo
import net.corda.core.internal.div
import net.corda.core.schemas.MappedSchema
@ -147,20 +147,20 @@ private fun handleCommand(options: OptionSet, baseDirectory: Path, configFile: P
}
}
options.has(RUN_MIGRATION) -> {
logger.info("Running the database migration on ${baseDirectory}")
logger.info("Running the database migration on $baseDirectory")
runMigrationCommand { it.runMigration() }
}
options.has(CREATE_MIGRATION_CORDAPP) && (mode == Mode.NODE) -> {
fun generateMigrationFileForSchema(schemaClass: String) {
logger.info("Creating database migration files for schema: ${schemaClass} into ${baseDirectory / "migration"}")
logger.info("Creating database migration files for schema: $schemaClass into ${baseDirectory / "migration"}")
try {
runWithDataSource(config) {
MigrationExporter(baseDirectory, config.dataSourceProperties, classLoader, it).generateMigrationForCorDapp(schemaClass)
}
} catch (e: Exception) {
e.printStackTrace()
errorAndExit("Could not generate migration for ${schemaClass}: ${e.message}")
errorAndExit("Could not generate migration for $schemaClass: ${e.message}")
}
}