Search in sources :

Example 41 with FlywayException

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);
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) MigrationExecutor(org.flywaydb.core.api.resolver.MigrationExecutor) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)

Example 42 with FlywayException

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);
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

FlywayException (org.flywaydb.core.api.FlywayException)42 IOException (java.io.IOException)13 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)6 MigrationVersion (org.flywaydb.core.api.MigrationVersion)6 Test (org.junit.Test)6 File (java.io.File)5 InputStreamReader (java.io.InputStreamReader)5 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)5 FileInputStream (java.io.FileInputStream)4 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)4 StringReader (java.io.StringReader)3 Method (java.lang.reflect.Method)3 URL (java.net.URL)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)3 DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)3 TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)3