Search in sources :

Example 11 with FlywaySqlException

use of org.flywaydb.core.internal.exception.FlywaySqlException in project flyway by flyway.

the class DbClean method dropSchema.

private void dropSchema(final Schema schema, CleanResult cleanResult) {
    LOG.debug("Dropping schema " + schema + "...");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    try {
        ExecutionTemplateFactory.createExecutionTemplate(connection.getJdbcConnection(), database).execute(() -> {
            schema.drop();
            return null;
        });
        cleanResult.schemasDropped.add(schema.getName());
        stopWatch.stop();
        LOG.info(String.format("Successfully dropped schema %s (execution time %s)", schema, TimeFormat.format(stopWatch.getTotalTimeMillis())));
    } catch (FlywaySqlException e) {
        LOG.debug(e.getMessage());
        LOG.warn("Unable to drop schema " + schema + ". It was cleaned instead.");
        cleanResult.schemasCleaned.add(schema.getName());
    }
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) StopWatch(org.flywaydb.core.internal.util.StopWatch)

Example 12 with FlywaySqlException

use of org.flywaydb.core.internal.exception.FlywaySqlException in project flyway by flyway.

the class Schema method allTypes.

/**
 * Retrieves all the types in this schema.
 */
protected final Type[] allTypes() {
    ResultSet resultSet = null;
    try {
        resultSet = database.jdbcMetaData.getUDTs(null, name, null, null);
        List<Type> types = new ArrayList<>();
        while (resultSet.next()) {
            types.add(getType(resultSet.getString("TYPE_NAME")));
        }
        return types.toArray(new Type[0]);
    } catch (SQLException e) {
        throw new FlywaySqlException("Unable to retrieve all types in schema " + this, e);
    } finally {
        JdbcUtils.closeResultSet(resultSet);
    }
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 13 with FlywaySqlException

use of org.flywaydb.core.internal.exception.FlywaySqlException in project flyway by flyway.

the class Schema method create.

/**
 * Creates this schema in the database.
 */
public void create() {
    try {
        LOG.info("Creating schema " + this + " ...");
        doCreate();
    } catch (SQLException e) {
        throw new FlywaySqlException("Unable to create schema " + this, e);
    }
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) SQLException(java.sql.SQLException)

Example 14 with FlywaySqlException

use of org.flywaydb.core.internal.exception.FlywaySqlException in project flyway by flyway.

the class Table method unlock.

/**
 * For databases that require an explicit unlocking, not an implicit end-of-transaction one.
 */
public void unlock() {
    // lockDepth can be zero if this table didn't exist at the time of the call to lock()
    if (!exists() || lockDepth == 0) {
        return;
    }
    try {
        doUnlock();
        lockDepth--;
    } catch (SQLException e) {
        throw new FlywaySqlException("Unable to unlock table " + this, e);
    }
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) SQLException(java.sql.SQLException)

Example 15 with FlywaySqlException

use of org.flywaydb.core.internal.exception.FlywaySqlException in project flyway by flyway.

the class JdbcTableSchemaHistory method delete.

@Override
public void delete(AppliedMigration appliedMigration) {
    connection.restoreOriginalState();
    clearCache();
    MigrationVersion version = appliedMigration.getVersion();
    String versionStr = version == null ? null : version.toString();
    if (version == null) {
        LOG.info("Repairing Schema History table for description \"" + appliedMigration.getDescription() + "\" (Marking as DELETED)  ...");
    } else {
        LOG.info("Repairing Schema History table for version \"" + version + "\" (Marking as DELETED)  ...");
    }
    Object versionObj = versionStr == null ? JdbcNullTypes.StringNull : versionStr;
    Object checksumObj = appliedMigration.getChecksum() == null ? JdbcNullTypes.IntegerNull : appliedMigration.getChecksum();
    try {
        jdbcTemplate.update(database.getInsertStatement(table), calculateInstalledRank(), versionObj, appliedMigration.getDescription(), "DELETE", appliedMigration.getScript(), checksumObj, database.getInstalledBy(), 0, appliedMigration.isSuccess());
    } catch (SQLException e) {
        throw new FlywaySqlException("Unable to repair Schema History table " + table + " for version " + version, e);
    }
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException)

Aggregations

FlywaySqlException (org.flywaydb.core.internal.exception.FlywaySqlException)17 SQLException (java.sql.SQLException)13 ResultSet (java.sql.ResultSet)3 FlywayException (org.flywaydb.core.api.FlywayException)3 MigrationVersion (org.flywaydb.core.api.MigrationVersion)3 StopWatch (org.flywaydb.core.internal.util.StopWatch)3 MigrationType (org.flywaydb.core.api.MigrationType)2 JdbcTemplate (org.flywaydb.core.internal.jdbc.JdbcTemplate)2 RowMapper (org.flywaydb.core.internal.jdbc.RowMapper)2 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 CustomLog (lombok.CustomLog)1 MigrationPattern (org.flywaydb.core.api.MigrationPattern)1 CommandResultFactory (org.flywaydb.core.api.output.CommandResultFactory)1 RepairOutput (org.flywaydb.core.api.output.RepairOutput)1 RepairResult (org.flywaydb.core.api.output.RepairResult)1