use of org.flywaydb.core.internal.command.DbRepair in project flyway by flyway.
the class Flyway method execute.
/**
* Executes this command with proper resource handling and cleanup.
*
* @param command The command to execute.
* @param <T> The type of the result.
* @return The result of the command.
*/
/*private -> testing*/
<T> T execute(Command<T> command) {
T result;
VersionPrinter.printVersion();
Connection connectionMetaDataTable = null;
try {
if (dataSource == null) {
throw new FlywayException("Unable to connect to the database. Configure the url, user and password!");
}
connectionMetaDataTable = JdbcUtils.openConnection(dataSource);
DbSupport dbSupport = DbSupportFactory.createDbSupport(connectionMetaDataTable, !dbConnectionInfoPrinted);
dbConnectionInfoPrinted = true;
LOG.debug("DDL Transactions Supported: " + dbSupport.supportsDdlTransactions());
if (schemaNames.length == 0) {
Schema currentSchema = dbSupport.getOriginalSchema();
if (currentSchema == null) {
throw new FlywayException("Unable to determine schema for the metadata table." + " Set a default schema for the connection or specify one using the schemas property!");
}
setSchemas(currentSchema.getName());
}
if (schemaNames.length == 1) {
LOG.debug("Schema: " + schemaNames[0]);
} else {
LOG.debug("Schemas: " + StringUtils.arrayToCommaDelimitedString(schemaNames));
}
Schema[] schemas = new Schema[schemaNames.length];
for (int i = 0; i < schemaNames.length; i++) {
schemas[i] = dbSupport.getSchema(schemaNames[i]);
}
Scanner scanner = new Scanner(classLoader);
MigrationResolver migrationResolver = createMigrationResolver(dbSupport, scanner);
if (!skipDefaultCallbacks) {
Set<FlywayCallback> flywayCallbacks = new LinkedHashSet<FlywayCallback>(Arrays.asList(callbacks));
flywayCallbacks.add(new SqlScriptFlywayCallback(dbSupport, scanner, locations, createPlaceholderReplacer(), this));
callbacks = flywayCallbacks.toArray(new FlywayCallback[flywayCallbacks.size()]);
}
for (FlywayCallback callback : callbacks) {
ConfigurationInjectionUtils.injectFlywayConfiguration(callback, this);
}
MetaDataTable metaDataTable = new MetaDataTableImpl(dbSupport, schemas[0].getTable(table), installedBy);
if (metaDataTable.upgradeIfNecessary()) {
new DbRepair(dbSupport, connectionMetaDataTable, schemas[0], migrationResolver, metaDataTable, callbacks).repairChecksumsAndDescriptions();
LOG.info("Metadata table " + table + " successfully upgraded to the Flyway 4.0 format.");
}
result = command.execute(connectionMetaDataTable, migrationResolver, metaDataTable, dbSupport, schemas, callbacks);
} finally {
JdbcUtils.closeConnection(connectionMetaDataTable);
}
return result;
}
Aggregations