use of org.flywaydb.core.api.MigrationInfoService in project incubator-gobblin by apache.
the class DatabaseJobHistoryStore method getDatabaseVersion.
private static MigrationVersion getDatabaseVersion(DataSource dataSource) throws FlywayException {
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
MigrationInfoService info = flyway.info();
MigrationVersion currentVersion = MigrationVersion.EMPTY;
if (info.current() != null) {
currentVersion = info.current().getVersion();
}
return currentVersion;
}
use of org.flywaydb.core.api.MigrationInfoService in project flyway by flyway.
the class FlywayInfoTask method run.
@Override
protected Object run(Flyway flyway) {
MigrationInfoService info = flyway.info();
MigrationInfo current = info.current();
MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
System.out.println("Schema version: " + currentSchemaVersion);
System.out.println(MigrationInfoDumper.dumpToAsciiTable(info.all()));
return info;
}
use of org.flywaydb.core.api.MigrationInfoService in project keywhiz by square.
the class PreviewMigrateCommand method run.
@Override
protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception {
DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "migration-preview-datasource");
Flyway flyway = Flyway.configure().dataSource(dataSource).locations(config.getMigrationsDir()).table(config.getFlywaySchemaTable()).load();
MigrationInfoService info = flyway.info();
MigrationInfo current = info.current();
if (current == null) {
logger.info("No migrations have been run yet.");
} else {
logger.info("Currently applied migration:");
logger.info("* {} - {}", current.getVersion(), current.getDescription());
}
if (info.pending().length > 0) {
logger.info("Pending migrations:");
for (MigrationInfo migration : info.pending()) {
logger.info("* {} - {}", migration.getVersion(), migration.getDescription());
}
} else {
logger.info("No pending migrations");
}
}
use of org.flywaydb.core.api.MigrationInfoService in project flyway by flyway.
the class Flyway method info.
/**
* <p>Retrieves the complete information about all the migrations including applied, pending and current migrations with
* details and status.</p>
* <img src="https://flywaydb.org/assets/balsamiq/command-info.png" alt="info">
*
* @return All migrations sorted by version, oldest first.
* @throws FlywayException when the info retrieval failed.
*/
public MigrationInfoService info() {
return execute(new Command<MigrationInfoService>() {
public MigrationInfoService execute(final Connection connectionMetaDataTable, MigrationResolver migrationResolver, MetaDataTable metaDataTable, final DbSupport dbSupport, final Schema[] schemas, FlywayCallback[] flywayCallbacks) {
try {
for (final FlywayCallback callback : flywayCallbacks) {
new TransactionTemplate(connectionMetaDataTable).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schemas[0]);
callback.beforeInfo(connectionMetaDataTable);
return null;
}
});
}
MigrationInfoServiceImpl migrationInfoService = new MigrationInfoServiceImpl(migrationResolver, metaDataTable, target, outOfOrder, true, true, true);
migrationInfoService.refresh();
for (final FlywayCallback callback : flywayCallbacks) {
new TransactionTemplate(connectionMetaDataTable).execute(new Callable<Object>() {
@Override
public Object call() throws SQLException {
dbSupport.changeCurrentSchemaTo(schemas[0]);
callback.afterInfo(connectionMetaDataTable);
return null;
}
});
}
return migrationInfoService;
} finally {
dbSupport.restoreCurrentSchema();
}
}
});
}
use of org.flywaydb.core.api.MigrationInfoService in project flyway by flyway.
the class InfoServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MigrationInfoService migrationInfoService = flyway.info();
response.setContentType("application/json");
PrintWriter writer = response.getWriter();
writer.print("{\"status\":\"OK\", \"rows\":[");
boolean first = true;
for (MigrationInfo migrationInfo : migrationInfoService.all()) {
if (!first) {
writer.print(",");
}
writer.print("{\"version\":\"" + migrationInfo.getVersion() + "\",");
String description = migrationInfo.getDescription() == null ? "" : migrationInfo.getDescription();
writer.print("\"description\":\"" + description + "\",");
writer.print("\"script\":\"" + migrationInfo.getScript() + "\",");
writer.print("\"type\":\"" + migrationInfo.getType() + "\",");
writer.print("\"installedOn\":\"" + DateUtils.formatDateAsIsoString(migrationInfo.getInstalledOn()) + "\",");
writer.print("\"state\":\"" + migrationInfo.getState().name() + "\"}");
first = false;
}
writer.print("]}");
}
Aggregations