Search in sources :

Example 6 with MigrationResolver

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

the class CompositeMigrationResolverSmallTest method resolveMigrationsMultipleLocations.

@Test
public void resolveMigrationsMultipleLocations() {
    FlywayConfigurationForTests config = FlywayConfigurationForTests.create();
    PlaceholderReplacer placeholderReplacer = new PlaceholderReplacer(new HashMap<String, String>(), "${", "}");
    MigrationResolver migrationResolver = new CompositeMigrationResolver(null, new Scanner(Thread.currentThread().getContextClassLoader()), config, new Locations("migration/subdir/dir2", "migration.outoforder", "migration/subdir/dir1"), placeholderReplacer, new MyCustomMigrationResolver());
    Collection<ResolvedMigration> migrations = migrationResolver.resolveMigrations();
    List<ResolvedMigration> migrationList = new ArrayList<ResolvedMigration>(migrations);
    assertEquals(4, migrations.size());
    assertEquals("First", migrationList.get(0).getDescription());
    assertEquals("Late arrivals", migrationList.get(1).getDescription());
    assertEquals("Virtual Migration", migrationList.get(2).getDescription());
    assertEquals("Add foreign key", migrationList.get(3).getDescription());
}
Also used : Scanner(org.flywaydb.core.internal.util.scanner.Scanner) PlaceholderReplacer(org.flywaydb.core.internal.util.PlaceholderReplacer) Locations(org.flywaydb.core.internal.util.Locations) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) MigrationResolver(org.flywaydb.core.api.resolver.MigrationResolver) Test(org.junit.Test)

Example 7 with MigrationResolver

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

the class CompositeMigrationResolverSmallTest method collectMigrationsExactDuplicatesInDifferentLocations.

/**
     * Checks that migrations are properly collected, eliminating all exact duplicates.
     */
@Test
public void collectMigrationsExactDuplicatesInDifferentLocations() {
    MigrationResolver migrationResolver = new MigrationResolver() {

        public List<ResolvedMigration> resolveMigrations() {
            ResolvedMigrationImpl testMigration = createTestMigration(MigrationType.SQL, "2", "Description2", "Migration2", 1234);
            testMigration.setPhysicalLocation("abc");
            ResolvedMigrationImpl testMigration2 = createTestMigration(MigrationType.SQL, "2", "Description2", "Migration2", 1234);
            testMigration2.setPhysicalLocation("xyz");
            List<ResolvedMigration> migrations = new ArrayList<ResolvedMigration>();
            migrations.add(testMigration);
            migrations.add(testMigration2);
            return migrations;
        }
    };
    MigrationResolver migrationResolver2 = new MigrationResolver() {

        public List<ResolvedMigration> resolveMigrations() {
            List<ResolvedMigration> migrations = new ArrayList<ResolvedMigration>();
            ResolvedMigrationImpl testMigration = createTestMigration(MigrationType.SQL, "2", "Description2", "Migration2", 1234);
            testMigration.setPhysicalLocation("def");
            migrations.add(testMigration);
            return migrations;
        }
    };
    Collection<MigrationResolver> migrationResolvers = Arrays.asList(migrationResolver, migrationResolver2);
    Collection<ResolvedMigration> migrations = CompositeMigrationResolver.collectMigrations(migrationResolvers);
    assertEquals(1, migrations.size());
}
Also used : ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) MigrationResolver(org.flywaydb.core.api.resolver.MigrationResolver) Test(org.junit.Test)

Aggregations

MigrationResolver (org.flywaydb.core.api.resolver.MigrationResolver)7 Test (org.junit.Test)5 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)4 Connection (java.sql.Connection)3 FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)3 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)3 Schema (org.flywaydb.core.internal.dbsupport.Schema)3 MetaDataTable (org.flywaydb.core.internal.metadatatable.MetaDataTable)3 Scanner (org.flywaydb.core.internal.util.scanner.Scanner)3 SqlScriptFlywayCallback (org.flywaydb.core.internal.callback.SqlScriptFlywayCallback)2 CompositeMigrationResolver (org.flywaydb.core.internal.resolver.CompositeMigrationResolver)2 Locations (org.flywaydb.core.internal.util.Locations)2 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 Callable (java.util.concurrent.Callable)1 FlywayException (org.flywaydb.core.api.FlywayException)1 MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)1 DbRepair (org.flywaydb.core.internal.command.DbRepair)1 MigrationInfoServiceImpl (org.flywaydb.core.internal.info.MigrationInfoServiceImpl)1 MetaDataTableImpl (org.flywaydb.core.internal.metadatatable.MetaDataTableImpl)1