use of org.flywaydb.core.api.FlywayException in project killbill by killbill.
the class DbMigrateWithDryRun method applyMigration.
private void applyMigration(final int installedRnk, final MigrationInfoImpl migration) {
final MigrationVersion version = migration.getVersion();
final String migrationText;
if (version != null) {
migrationText = "schema " + schema + " to version " + version + " - " + migration.getDescription();
} else {
migrationText = "schema " + schema + " with repeatable migration " + migration.getDescription();
}
LOG.info("Migrating " + migrationText);
// PIERRE: override the executor to capture the SQL
final FileSystemResource sqlScriptResource = new FileSystemResource(migration.getResolvedMigration().getPhysicalLocation());
final MigrationExecutor migrationExecutor = new CapturingSqlMigrationExecutor(sqlStatements, dbSupport, sqlScriptResource, placeholderReplacer, encoding);
try {
doMigrate(migration, migrationExecutor, migrationText);
} catch (final SQLException e) {
throw new FlywayException("Unable to apply migration", e);
}
final AppliedMigration appliedMigration = new AppliedMigration(installedRnk, version, migration.getDescription(), migration.getType(), migration.getScript(), migration.getResolvedMigration().getChecksum(), null, null, -1, true);
metaDataTableForDryRun.addAppliedMigration(appliedMigration);
}
use of org.flywaydb.core.api.FlywayException in project killbill by killbill.
the class Migrator method loadConfigurationFile.
/**
* Loads the configuration from the configuration file. If a configuration file is specified using the -configfile
* argument it will be used, otherwise the default config file (conf/flyway.properties) will be loaded.
*
* @param properties The properties object to load to configuration into.
* @param file The configuration file to load.
* @param encoding The encoding of the configuration file.
* @param failIfMissing Whether to fail if the file is missing.
* @return Whether the file was loaded successfully.
* @throws FlywayException when the configuration file could not be loaded.
*/
private static boolean loadConfigurationFile(final Properties properties, final String file, final String encoding, final boolean failIfMissing) throws FlywayException {
final File configFile = new File(file);
final String errorMessage = "Unable to load config file: " + configFile.getAbsolutePath();
if (!configFile.isFile() || !configFile.canRead()) {
if (!failIfMissing) {
LOG.debug(errorMessage);
return false;
}
throw new FlywayException(errorMessage);
}
LOG.debug("Loading config file: " + configFile.getAbsolutePath());
try {
final String contents = FileCopyUtils.copyToString(new InputStreamReader(new FileInputStream(configFile), encoding));
properties.load(new StringReader(contents.replace("\\", "\\\\")));
return true;
} catch (final IOException e) {
throw new FlywayException(errorMessage, e);
}
}
Aggregations