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());
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations