Search in sources :

Example 1 with MigrationInfoImpl

use of org.flywaydb.core.internal.info.MigrationInfoImpl in project killbill by killbill.

the class DbMigrateWithDryRun method dryRunMigrate.

public int dryRunMigrate() throws FlywayException {
    try {
        for (final FlywayCallback callback : callbacks) {
            new TransactionTemplate(connectionUserObjects).execute(new TransactionCallback<Object>() {

                @Override
                public Object doInTransaction() throws SQLException {
                    dbSupportUserObjects.changeCurrentSchemaTo(schema);
                    callback.beforeMigrate(connectionUserObjects);
                    return null;
                }
            });
        }
        // PIERRE: perform a single query to the metadata table
        final MigrationInfoServiceImpl infoService = new MigrationInfoServiceImpl(migrationResolver, metaDataTableForDryRun, target, outOfOrder, true, true);
        infoService.refresh();
        final MigrationInfoImpl[] pendingMigrations = infoService.pending();
        new TransactionTemplate(connectionMetaDataTable, false).execute(new TransactionCallback<Boolean>() {

            public Boolean doInTransaction() {
                int i = 1;
                for (final MigrationInfoImpl migrationInfo : pendingMigrations) {
                    applyMigration(i, migrationInfo);
                    i++;
                }
                return true;
            }
        });
        for (final FlywayCallback callback : callbacks) {
            new TransactionTemplate(connectionUserObjects).execute(new TransactionCallback<Object>() {

                @Override
                public Object doInTransaction() throws SQLException {
                    dbSupportUserObjects.changeCurrentSchemaTo(schema);
                    callback.afterMigrate(connectionUserObjects);
                    return null;
                }
            });
        }
        return pendingMigrations.length;
    } finally {
        dbSupportUserObjects.restoreCurrentSchema();
    }
}
Also used : MigrationInfoServiceImpl(org.flywaydb.core.internal.info.MigrationInfoServiceImpl) FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) SQLException(java.sql.SQLException) MigrationInfoImpl(org.flywaydb.core.internal.info.MigrationInfoImpl) TransactionTemplate(org.flywaydb.core.internal.util.jdbc.TransactionTemplate)

Example 2 with MigrationInfoImpl

use of org.flywaydb.core.internal.info.MigrationInfoImpl in project flyway by flyway.

the class DbRepair method repairChecksumsAndDescriptions.

public void repairChecksumsAndDescriptions() {
    migrationInfoService.refresh();
    for (MigrationInfo migrationInfo : migrationInfoService.all()) {
        MigrationInfoImpl migrationInfoImpl = (MigrationInfoImpl) migrationInfo;
        ResolvedMigration resolved = migrationInfoImpl.getResolvedMigration();
        AppliedMigration applied = migrationInfoImpl.getAppliedMigration();
        if (resolved != null && applied != null && resolved.getVersion() != null) {
            if (!ObjectUtils.nullSafeEquals(resolved.getChecksum(), applied.getChecksum()) || !ObjectUtils.nullSafeEquals(resolved.getDescription(), applied.getDescription())) {
                metaDataTable.update(migrationInfoImpl.getVersion(), resolved.getDescription(), resolved.getChecksum());
            }
        }
    }
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrationInfoImpl(org.flywaydb.core.internal.info.MigrationInfoImpl) AppliedMigration(org.flywaydb.core.internal.metadatatable.AppliedMigration) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration)

Aggregations

MigrationInfoImpl (org.flywaydb.core.internal.info.MigrationInfoImpl)2 SQLException (java.sql.SQLException)1 MigrationInfo (org.flywaydb.core.api.MigrationInfo)1 FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)1 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)1 MigrationInfoServiceImpl (org.flywaydb.core.internal.info.MigrationInfoServiceImpl)1 AppliedMigration (org.flywaydb.core.internal.metadatatable.AppliedMigration)1 TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)1