Search in sources :

Example 1 with MigrationInfoService

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;
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationVersion(org.flywaydb.core.api.MigrationVersion) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService)

Example 2 with MigrationInfoService

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;
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationVersion(org.flywaydb.core.api.MigrationVersion) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService)

Example 3 with MigrationInfoService

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");
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService) MetricRegistry(com.codahale.metrics.MetricRegistry) DataSource(javax.sql.DataSource)

Example 4 with MigrationInfoService

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();
            }
        }
    });
}
Also used : MigrationInfoServiceImpl(org.flywaydb.core.internal.info.MigrationInfoServiceImpl) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService) MetaDataTable(org.flywaydb.core.internal.metadatatable.MetaDataTable) Schema(org.flywaydb.core.internal.dbsupport.Schema) Connection(java.sql.Connection) TransactionTemplate(org.flywaydb.core.internal.util.jdbc.TransactionTemplate) Callable(java.util.concurrent.Callable) FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) SqlScriptFlywayCallback(org.flywaydb.core.internal.callback.SqlScriptFlywayCallback) DbSupport(org.flywaydb.core.internal.dbsupport.DbSupport) MigrationResolver(org.flywaydb.core.api.resolver.MigrationResolver) CompositeMigrationResolver(org.flywaydb.core.internal.resolver.CompositeMigrationResolver)

Example 5 with MigrationInfoService

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("]}");
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService) PrintWriter(java.io.PrintWriter)

Aggregations

MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)7 MigrationInfo (org.flywaydb.core.api.MigrationInfo)4 MigrationVersion (org.flywaydb.core.api.MigrationVersion)3 Flyway (org.flywaydb.core.Flyway)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 PrintWriter (java.io.PrintWriter)1 Connection (java.sql.Connection)1 Callable (java.util.concurrent.Callable)1 DataSource (javax.sql.DataSource)1 FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)1 MigrationResolver (org.flywaydb.core.api.resolver.MigrationResolver)1 SqlScriptFlywayCallback (org.flywaydb.core.internal.callback.SqlScriptFlywayCallback)1 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)1 Schema (org.flywaydb.core.internal.dbsupport.Schema)1 MigrationInfoServiceImpl (org.flywaydb.core.internal.info.MigrationInfoServiceImpl)1 MetaDataTable (org.flywaydb.core.internal.metadatatable.MetaDataTable)1 CompositeMigrationResolver (org.flywaydb.core.internal.resolver.CompositeMigrationResolver)1 TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)1