use of org.flywaydb.core.api.resolver.ResolvedMigration in project che by eclipse.
the class CustomSqlMigrationResolver method resolveSqlMigrations.
private List<ResolvedMigration> resolveSqlMigrations() throws IOException, SQLException {
LOG.info("Searching for sql scripts in locations {}", Arrays.toString(flywayConfiguration.getLocations()));
final Map<Location, List<Resource>> allResources = finder.findResources(flywayConfiguration);
LOG.debug("Found scripts: {}", allResources);
final Map<String, Map<String, SqlScript>> scriptsInDir = new HashMap<>();
for (Location location : allResources.keySet()) {
final List<Resource> resources = allResources.get(location);
for (Resource resource : resources) {
final SqlScript newScript = scriptsCreator.createScript(location, resource);
if (!scriptsInDir.containsKey(newScript.dir)) {
scriptsInDir.put(newScript.dir, new HashMap<>(4));
}
final Map<String, SqlScript> existingScripts = scriptsInDir.get(newScript.dir);
final SqlScript existingScript = existingScripts.get(newScript.name);
if (existingScript == null) {
existingScripts.put(newScript.name, newScript);
} else if (Objects.equals(existingScript.vendor, newScript.vendor)) {
throw new FlywayException(format("More than one script with name '%s' is registered for " + "database vendor '%s', script '%s' conflicts with '%s'", newScript.name, existingScript.vendor, newScript, existingScript));
} else if (vendorName.equals(newScript.vendor)) {
existingScripts.put(newScript.name, newScript);
}
}
}
final Map<MigrationVersion, ResolvedMigration> migrations = new HashMap<>();
for (SqlScript script : scriptsInDir.values().stream().flatMap(scripts -> scripts.values().stream()).collect(toList())) {
final ResolvedMigrationImpl migration = new ResolvedMigrationImpl();
migration.setVersion(versionResolver.resolve(script, flywayConfiguration));
migration.setScript(script.resource.getLocation());
migration.setPhysicalLocation(script.resource.getLocationOnDisk());
migration.setType(MigrationType.SQL);
migration.setDescription(script.name);
migration.setChecksum(ByteSource.wrap(script.resource.loadAsBytes()).hash(Hashing.crc32()).asInt());
migration.setExecutor(new SqlMigrationExecutor(dbSupport, script.resource, placeholderReplacer, flywayConfiguration.getEncoding()));
if (migrations.put(migration.getVersion(), migration) != null) {
throw new FlywayException("Two migrations with the same version detected");
}
}
return new ArrayList<>(migrations.values());
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class JdbcMigrationResolver method resolveMigrations.
@Override
public List<ResolvedMigration> resolveMigrations() {
List<ResolvedMigration> migrations = new ArrayList<ResolvedMigration>();
if (!location.isClassPath()) {
return migrations;
}
try {
Class<?>[] classes = scanner.scanForClasses(location, JdbcMigration.class);
for (Class<?> clazz : classes) {
JdbcMigration jdbcMigration = ClassUtils.instantiate(clazz.getName(), scanner.getClassLoader());
ConfigurationInjectionUtils.injectFlywayConfiguration(jdbcMigration, configuration);
ResolvedMigrationImpl migrationInfo = extractMigrationInfo(jdbcMigration);
migrationInfo.setPhysicalLocation(ClassUtils.getLocationOnDisk(clazz));
migrationInfo.setExecutor(new JdbcMigrationExecutor(jdbcMigration));
migrations.add(migrationInfo);
}
} catch (Exception e) {
throw new FlywayException("Unable to resolve Jdbc Java migrations in location: " + location + " (" + e.getMessage() + ")", e);
}
Collections.sort(migrations, new ResolvedMigrationComparator());
return migrations;
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class SpringJdbcMigrationResolver method resolveMigrations.
@Override
public Collection<ResolvedMigration> resolveMigrations() {
List<ResolvedMigration> migrations = new ArrayList<ResolvedMigration>();
if (!location.isClassPath()) {
return migrations;
}
try {
Class<?>[] classes = scanner.scanForClasses(location, SpringJdbcMigration.class);
for (Class<?> clazz : classes) {
SpringJdbcMigration springJdbcMigration = ClassUtils.instantiate(clazz.getName(), scanner.getClassLoader());
ConfigurationInjectionUtils.injectFlywayConfiguration(springJdbcMigration, configuration);
ResolvedMigrationImpl migrationInfo = extractMigrationInfo(springJdbcMigration);
migrationInfo.setPhysicalLocation(ClassUtils.getLocationOnDisk(clazz));
migrationInfo.setExecutor(new SpringJdbcMigrationExecutor(springJdbcMigration));
migrations.add(migrationInfo);
}
} catch (Exception e) {
throw new FlywayException("Unable to resolve Spring Jdbc Java migrations in location: " + location, e);
}
Collections.sort(migrations, new ResolvedMigrationComparator());
return migrations;
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class MigrationInfoImplSmallTest method compareToRepeatable.
@Test
public void compareToRepeatable() {
ResolvedMigration b = createResolvedMigration(null, "B");
MigrationInfoContext context = new MigrationInfoContext();
context.target = MigrationVersion.LATEST;
context.latestRepeatableRuns.put("A", 10);
context.latestRepeatableRuns.put("B", 7);
context.latestRepeatableRuns.put("C", 5);
MigrationInfoImpl r1 = new MigrationInfoImpl(createResolvedMigration(null, "C"), createAppliedMigration(5, null, "C"), context, false);
MigrationInfoImpl v2 = new MigrationInfoImpl(createResolvedMigration("1", "V1"), createAppliedMigration(6, "1", "V1"), context, false);
MigrationInfoImpl r3 = new MigrationInfoImpl(b, createAppliedMigration(7, null, "B", 123), context, false);
MigrationInfoImpl r4 = new MigrationInfoImpl(createResolvedMigration(null, "A"), createAppliedMigration(10, null, "A"), context, false);
MigrationInfoImpl r6 = new MigrationInfoImpl(b, null, context, false);
MigrationInfoImpl v5 = new MigrationInfoImpl(createResolvedMigration("6", "V2"), null, context, false);
assertTrue(r1.compareTo(r1) == 0);
assertTrue(r1.compareTo(v2) < 0);
assertTrue(r1.compareTo(r3) < 0);
assertTrue(r1.compareTo(r4) < 0);
assertTrue(r1.compareTo(v5) < 0);
assertTrue(r1.compareTo(r6) < 0);
assertTrue(v2.compareTo(r1) > 0);
assertTrue(v2.compareTo(v2) == 0);
assertTrue(v2.compareTo(r3) < 0);
assertTrue(v2.compareTo(r4) < 0);
assertTrue(v2.compareTo(v5) < 0);
assertTrue(v2.compareTo(r6) < 0);
assertTrue(r3.compareTo(r1) > 0);
assertTrue(r3.compareTo(v2) > 0);
assertTrue(r3.compareTo(r3) == 0);
assertTrue(r3.compareTo(r4) < 0);
assertTrue(r3.compareTo(v5) < 0);
assertTrue(r3.compareTo(r6) < 0);
assertTrue(r4.compareTo(r1) > 0);
assertTrue(r4.compareTo(v2) > 0);
assertTrue(r4.compareTo(r3) > 0);
assertTrue(r4.compareTo(r4) == 0);
assertTrue(r4.compareTo(v5) < 0);
assertTrue(r4.compareTo(r6) < 0);
assertTrue(v5.compareTo(r1) > 0);
assertTrue(v5.compareTo(v2) > 0);
assertTrue(v5.compareTo(r3) > 0);
assertTrue(v5.compareTo(r4) > 0);
assertTrue(v5.compareTo(v5) == 0);
assertTrue(v5.compareTo(r6) < 0);
assertTrue(r6.compareTo(r1) > 0);
assertTrue(r6.compareTo(v2) > 0);
assertTrue(r6.compareTo(r3) > 0);
assertTrue(r6.compareTo(r4) > 0);
assertTrue(r6.compareTo(v5) > 0);
assertTrue(r6.compareTo(r6) == 0);
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class CompositeMigrationResolverSmallTest method skipDefaultResolvers.
@Test
public void skipDefaultResolvers() {
FlywayConfigurationForTests config = FlywayConfigurationForTests.create();
config.setSkipDefaultResolvers(true);
MigrationResolver migrationResolver = new CompositeMigrationResolver(null, new Scanner(Thread.currentThread().getContextClassLoader()), config, new Locations("migration/outoforder", "org/flywaydb/core/internal/resolver/jdbc/dummy"), PlaceholderReplacer.NO_PLACEHOLDERS);
Collection<ResolvedMigration> migrations = migrationResolver.resolveMigrations();
assertTrue(migrations.isEmpty());
}
Aggregations