use of org.flywaydb.core.internal.util.StopWatch in project flyway by flyway.
the class DbValidate method validate.
/**
* Starts the actual migration.
*
* @return The validation error, if any.
*/
public String validate() {
if (!schema.exists()) {
if (!migrationResolver.resolveMigrations().isEmpty() && !pending) {
return "Schema " + schema + " doesn't exist yet";
}
return null;
}
try {
for (final FlywayCallback callback : callbacks) {
new TransactionTemplate(connection).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schema);
callback.beforeValidate(connection);
return null;
}
});
}
LOG.debug("Validating migrations ...");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Pair<Integer, String> result = new TransactionTemplate(connection).execute(new Callable<Pair<Integer, String>>() {
@Override
public Pair<Integer, String> call() {
dbSupport.changeCurrentSchemaTo(schema);
MigrationInfoServiceImpl migrationInfoService = new MigrationInfoServiceImpl(migrationResolver, metaDataTable, target, outOfOrder, pending, missing, future);
migrationInfoService.refresh();
int count = migrationInfoService.all().length;
String validationError = migrationInfoService.validate();
return Pair.of(count, validationError);
}
});
stopWatch.stop();
String error = result.getRight();
if (error == null) {
int count = result.getLeft();
if (count == 1) {
LOG.info(String.format("Successfully validated 1 migration (execution time %s)", TimeFormat.format(stopWatch.getTotalTimeMillis())));
} else {
LOG.info(String.format("Successfully validated %d migrations (execution time %s)", count, TimeFormat.format(stopWatch.getTotalTimeMillis())));
}
}
for (final FlywayCallback callback : callbacks) {
new TransactionTemplate(connection).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schema);
callback.afterValidate(connection);
return null;
}
});
}
return error;
} finally {
dbSupport.restoreCurrentSchema();
}
}
Aggregations