Search in sources :

Example 11 with ResolvedMigration

use of org.flywaydb.core.api.resolver.ResolvedMigration 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)

Example 12 with ResolvedMigration

use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.

the class MigrationTestCase method assertChecksum.

/**
     * Compares the DB checksum to the classpath checksum of this migration.
     *
     * @param migrationInfo
     *            The migration to check.
     */
protected void assertChecksum(MigrationInfo migrationInfo) {
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(dbSupport, new Scanner(Thread.currentThread().getContextClassLoader()), new Location(getBasedir()), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.create());
    List<ResolvedMigration> migrations = sqlMigrationResolver.resolveMigrations();
    for (ResolvedMigration migration : migrations) {
        if (migration.getVersion().toString().equals(migrationInfo.getVersion().toString())) {
            assertEquals("Wrong checksum for " + migrationInfo.getScript(), migration.getChecksum(), migrationInfo.getChecksum());
        }
    }
}
Also used : Scanner(org.flywaydb.core.internal.util.scanner.Scanner) SqlMigrationResolver(org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) Location(org.flywaydb.core.internal.util.Location)

Example 13 with ResolvedMigration

use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.

the class SqlMigrationResolverMediumTest method resolveMigrations.

@Test
public void resolveMigrations() throws Exception {
    @SuppressWarnings("ConstantConditions") String path = URLDecoder.decode(getClass().getClassLoader().getResource("migration/subdir").getPath(), "UTF-8");
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, new Scanner(Thread.currentThread().getContextClassLoader()), new Location("filesystem:" + new File(path).getPath()), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.create());
    Collection<ResolvedMigration> migrations = sqlMigrationResolver.resolveMigrations();
    assertEquals(3, migrations.size());
    List<ResolvedMigration> migrationList = new ArrayList<ResolvedMigration>(migrations);
    assertEquals("1", migrationList.get(0).getVersion().toString());
    assertEquals("1.1", migrationList.get(1).getVersion().toString());
    assertEquals("2.0", migrationList.get(2).getVersion().toString());
    assertEquals("dir1/V1__First.sql", migrationList.get(0).getScript());
    assertEquals("V1_1__Populate_table.sql", migrationList.get(1).getScript());
    assertEquals("dir2/V2_0__Add_foreign_key.sql", migrationList.get(2).getScript());
}
Also used : Scanner(org.flywaydb.core.internal.util.scanner.Scanner) ArrayList(java.util.ArrayList) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) File(java.io.File) Location(org.flywaydb.core.internal.util.Location) Test(org.junit.Test)

Example 14 with ResolvedMigration

use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.

the class SqlMigrationResolverSmallTest method resolveMigrations.

@Test
public void resolveMigrations() {
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location("migration/subdir"), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.create());
    Collection<ResolvedMigration> migrations = sqlMigrationResolver.resolveMigrations();
    assertEquals(3, migrations.size());
    List<ResolvedMigration> migrationList = new ArrayList<ResolvedMigration>(migrations);
    assertEquals("1", migrationList.get(0).getVersion().toString());
    assertEquals("1.1", migrationList.get(1).getVersion().toString());
    assertEquals("2.0", migrationList.get(2).getVersion().toString());
    assertEquals("dir1/V1__First.sql", migrationList.get(0).getScript());
    assertEquals("V1_1__Populate_table.sql", migrationList.get(1).getScript());
    assertEquals("dir2/V2_0__Add_foreign_key.sql", migrationList.get(2).getScript());
}
Also used : ArrayList(java.util.ArrayList) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) Location(org.flywaydb.core.internal.util.Location) Test(org.junit.Test)

Example 15 with ResolvedMigration

use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.

the class JdbcMigrationResolverSmallTest method explicitInfo.

@Test
public void explicitInfo() {
    JdbcMigrationResolver jdbcMigrationResolver = new JdbcMigrationResolver(scanner, null, null);
    ResolvedMigration migrationInfo = jdbcMigrationResolver.extractMigrationInfo(new Version3dot5());
    assertEquals("3.5", migrationInfo.getVersion().toString());
    assertEquals("Three Dot Five", migrationInfo.getDescription());
    assertEquals(35, migrationInfo.getChecksum().intValue());
}
Also used : ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) Version3dot5(org.flywaydb.core.internal.resolver.jdbc.dummy.Version3dot5) Test(org.junit.Test)

Aggregations

ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)24 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)10 Location (org.flywaydb.core.internal.util.Location)7 Scanner (org.flywaydb.core.internal.util.scanner.Scanner)5 FlywayException (org.flywaydb.core.api.FlywayException)4 MigrationResolver (org.flywaydb.core.api.resolver.MigrationResolver)4 MigrationVersion (org.flywaydb.core.api.MigrationVersion)3 ResolvedMigrationComparator (org.flywaydb.core.internal.resolver.ResolvedMigrationComparator)3 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)3 Connection (java.sql.Connection)2 MigrationType (org.flywaydb.core.api.MigrationType)2 MigrationExecutor (org.flywaydb.core.api.resolver.MigrationExecutor)2 AppliedMigration (org.flywaydb.core.internal.metadatatable.AppliedMigration)2 SqlMigrationResolver (org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver)2 Locations (org.flywaydb.core.internal.util.Locations)2 PlaceholderReplacer (org.flywaydb.core.internal.util.PlaceholderReplacer)2 Hashing (com.google.common.hash.Hashing)1 ByteSource (com.google.common.io.ByteSource)1 File (java.io.File)1