Search in sources :

Example 41 with MigrationVersion

use of org.flywaydb.core.api.MigrationVersion in project flyway by flyway.

the class InfoMojo method doExecute.

@Override
protected void doExecute(Flyway flyway) {
    MigrationInfoService info = flyway.info();
    MigrationInfo current = info.current();
    MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion();
    log.info("Schema version: " + currentSchemaVersion);
    log.info("");
    log.info(MigrationInfoDumper.dumpToAsciiTable(info.all()));
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationVersion(org.flywaydb.core.api.MigrationVersion) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService)

Example 42 with MigrationVersion

use of org.flywaydb.core.api.MigrationVersion in project flyway by flyway.

the class MavenVersionChecker method checkForVersionUpdates.

public static void checkForVersionUpdates() {
    if (!canConnectToMaven()) {
        return;
    }
    try {
        URL url = new URL(FLYWAY_URL);
        @Cleanup(value = "disconnect") HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        StringBuilder response = new StringBuilder();
        try (BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
            String line;
            while ((line = rd.readLine()) != null) {
                response.append(line).append('\r');
            }
        }
        MavenObject obj = new Gson().fromJson(response.toString(), MavenObject.class);
        MigrationVersion current = MigrationVersion.fromVersion(VersionPrinter.getVersion());
        MigrationVersion latest = null;
        String groupID = "org.flywaydb";
        MavenDoc[] mavenDocs = obj.response.docs;
        for (MavenDoc mavenDoc : mavenDocs) {
            if (mavenDoc.g.equals(groupID)) {
                latest = MigrationVersion.fromVersion(mavenDoc.latestVersion);
                break;
            }
        }
        if (current.compareTo(latest) < 0) {
            LOG.warn("This version of Flyway is out of date. Upgrade to Flyway " + latest + ": " + FlywayDbWebsiteLinks.STAYING_UP_TO_DATE + "\n");
        }
    } catch (Exception ignored) {
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) Cleanup(lombok.Cleanup) URL(java.net.URL) MigrationVersion(org.flywaydb.core.api.MigrationVersion) BufferedReader(java.io.BufferedReader) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 43 with MigrationVersion

use of org.flywaydb.core.api.MigrationVersion 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);
    }
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException)

Example 44 with MigrationVersion

use of org.flywaydb.core.api.MigrationVersion in project killbill by killbill.

the class CapturingMetaDataTable method addAppliedMigration.

@Override
public void addAppliedMigration(final AppliedMigration appliedMigration) {
    final MigrationVersion version = appliedMigration.getVersion();
    final String versionStr = version == null ? null : version.toString();
    final int calculateInstalledRank;
    try {
        calculateInstalledRank = calculateInstalledRank();
    } catch (final SQLException e) {
        throw new RuntimeException(e);
    }
    final String sql = new StringBuilder().append("INSERT INTO ").append(table).append(" (").append(dbSupport.quote("installed_rank")).append(",").append(dbSupport.quote("version")).append(",").append(dbSupport.quote("description")).append(",").append(dbSupport.quote("type")).append(",").append(dbSupport.quote("script")).append(",").append(dbSupport.quote("checksum")).append(",").append(dbSupport.quote("installed_by")).append(",").append(dbSupport.quote("execution_time")).append(",").append(dbSupport.quote("success")).append(")").append(" VALUES (").append(calculateInstalledRank + appliedMigration.getInstalledRank()).append(",").append("'").append(versionStr).append("',").append("'").append(appliedMigration.getDescription()).append("',").append("'").append(appliedMigration.getType().name()).append("',").append("'").append(appliedMigration.getScript()).append("',").append(appliedMigration.getChecksum()).append(",").append(dbSupport.getCurrentUserFunction()).append(",").append(appliedMigration.getExecutionTime()).append(",").append(appliedMigration.isSuccess()).append(")").toString();
    sqlStatements.add(new SqlStatement(0, sql, false));
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException)

Example 45 with MigrationVersion

use of org.flywaydb.core.api.MigrationVersion in project killbill by killbill.

the class DbMigrateWithDryRun method applyMigration.

private void applyMigration(final int installedRnk, final MigrationInfoImpl migration) {
    final MigrationVersion version = migration.getVersion();
    final String migrationText;
    if (version != null) {
        migrationText = "schema " + schema + " to version " + version + " - " + migration.getDescription();
    } else {
        migrationText = "schema " + schema + " with repeatable migration " + migration.getDescription();
    }
    LOG.info("Migrating " + migrationText);
    // PIERRE: override the executor to capture the SQL
    final FileSystemResource sqlScriptResource = new FileSystemResource(migration.getResolvedMigration().getPhysicalLocation());
    final MigrationExecutor migrationExecutor = new CapturingSqlMigrationExecutor(sqlStatements, dbSupport, sqlScriptResource, placeholderReplacer, encoding);
    try {
        doMigrate(migration, migrationExecutor, migrationText);
    } catch (final SQLException e) {
        throw new FlywayException("Unable to apply migration", e);
    }
    final AppliedMigration appliedMigration = new AppliedMigration(installedRnk, version, migration.getDescription(), migration.getType(), migration.getScript(), migration.getResolvedMigration().getChecksum(), null, null, -1, true);
    metaDataTableForDryRun.addAppliedMigration(appliedMigration);
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) MigrationVersion(org.flywaydb.core.api.MigrationVersion) SQLException(java.sql.SQLException) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) MigrationExecutor(org.flywaydb.core.api.resolver.MigrationExecutor) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)

Aggregations

MigrationVersion (org.flywaydb.core.api.MigrationVersion)46 Test (org.junit.Test)27 SQLException (java.sql.SQLException)10 MigrationInfo (org.flywaydb.core.api.MigrationInfo)10 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)7 HashMap (java.util.HashMap)6 FlywayException (org.flywaydb.core.api.FlywayException)6 MigrationType (org.flywaydb.core.api.MigrationType)5 AppliedMigration (org.flywaydb.core.internal.metadatatable.AppliedMigration)5 MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)3 MigrationChecksumProvider (org.flywaydb.core.api.migration.MigrationChecksumProvider)3 MigrationInfoProvider (org.flywaydb.core.api.migration.MigrationInfoProvider)3 MigrationExecutor (org.flywaydb.core.api.resolver.MigrationExecutor)3 FlywaySqlScriptException (org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)2 FlywaySqlException (org.flywaydb.core.internal.dbsupport.FlywaySqlException)2 FlywaySqlException (org.flywaydb.core.internal.exception.FlywaySqlException)2 PlaceholderReplacer (org.flywaydb.core.internal.util.PlaceholderReplacer)2