use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class SpringJdbcMigrationResolverSmallTest method explicitInfo.
@Test
public void explicitInfo() {
SpringJdbcMigrationResolver springJdbcMigrationResolver = new SpringJdbcMigrationResolver(scanner, null, null);
ResolvedMigration migrationInfo = springJdbcMigrationResolver.extractMigrationInfo(new Version3dot5());
assertEquals("3.5", migrationInfo.getVersion().toString());
assertEquals("Three Dot Five", migrationInfo.getDescription());
assertEquals(35, migrationInfo.getChecksum().intValue());
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class MyCustomMigrationResolver method resolveMigrations.
@Override
public List<ResolvedMigration> resolveMigrations() {
List<ResolvedMigration> resolvedMigrations = new ArrayList<ResolvedMigration>();
resolvedMigrations.add(new ResolvedMigration() {
@Override
public MigrationVersion getVersion() {
return MigrationVersion.fromVersion("1.9");
}
@Override
public String getDescription() {
return "Virtual Migration";
}
@Override
public String getScript() {
return "VirtualScript 1.9";
}
@Override
public Integer getChecksum() {
return 19;
}
@Override
public MigrationType getType() {
return MigrationType.CUSTOM;
}
@Override
public String getPhysicalLocation() {
return "virtual://loaction";
}
@Override
public MigrationExecutor getExecutor() {
return new MigrationExecutor() {
@Override
public void execute(Connection connection) {
System.out.println("Executed !");
}
@Override
public boolean executeInTransaction() {
return true;
}
};
}
});
return resolvedMigrations;
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class MigrationInfoServiceImpl method refresh.
/**
* Refreshes the info about all known migrations from both the classpath and the DB.
*/
public void refresh() {
Collection<ResolvedMigration> availableMigrations = migrationResolver.resolveMigrations();
List<AppliedMigration> appliedMigrations = metaDataTable.allAppliedMigrations();
MigrationInfoContext context = new MigrationInfoContext();
context.outOfOrder = outOfOrder;
context.pending = pending;
context.missing = missing;
context.future = future;
context.target = target;
Map<MigrationVersion, ResolvedMigration> resolvedMigrationsMap = new TreeMap<MigrationVersion, ResolvedMigration>();
Map<String, ResolvedMigration> resolvedRepeatableMigrationsMap = new TreeMap<String, ResolvedMigration>();
for (ResolvedMigration resolvedMigration : availableMigrations) {
MigrationVersion version = resolvedMigration.getVersion();
if (version != null) {
if (version.compareTo(context.lastResolved) > 0) {
context.lastResolved = version;
}
resolvedMigrationsMap.put(version, resolvedMigration);
} else {
resolvedRepeatableMigrationsMap.put(resolvedMigration.getDescription(), resolvedMigration);
}
}
Map<MigrationVersion, Pair<AppliedMigration, Boolean>> appliedMigrationsMap = new TreeMap<MigrationVersion, Pair<AppliedMigration, Boolean>>();
List<AppliedMigration> appliedRepeatableMigrations = new ArrayList<AppliedMigration>();
for (AppliedMigration appliedMigration : appliedMigrations) {
MigrationVersion version = appliedMigration.getVersion();
boolean outOfOrder1 = false;
if (version != null) {
if (version.compareTo(context.lastApplied) > 0) {
context.lastApplied = version;
} else {
outOfOrder1 = true;
}
}
if (appliedMigration.getType() == MigrationType.SCHEMA) {
context.schema = version;
}
if (appliedMigration.getType() == MigrationType.BASELINE) {
context.baseline = version;
}
if (version != null) {
appliedMigrationsMap.put(version, Pair.of(appliedMigration, outOfOrder1));
} else {
appliedRepeatableMigrations.add(appliedMigration);
}
}
if (MigrationVersion.CURRENT == target) {
context.target = context.lastApplied;
}
Set<MigrationVersion> allVersions = new HashSet<MigrationVersion>();
allVersions.addAll(resolvedMigrationsMap.keySet());
allVersions.addAll(appliedMigrationsMap.keySet());
List<MigrationInfoImpl> migrationInfos1 = new ArrayList<MigrationInfoImpl>();
for (MigrationVersion version : allVersions) {
ResolvedMigration resolvedMigration = resolvedMigrationsMap.get(version);
Pair<AppliedMigration, Boolean> appliedMigrationInfo = appliedMigrationsMap.get(version);
if (appliedMigrationInfo == null) {
migrationInfos1.add(new MigrationInfoImpl(resolvedMigration, null, context, false));
} else {
migrationInfos1.add(new MigrationInfoImpl(resolvedMigration, appliedMigrationInfo.getLeft(), context, appliedMigrationInfo.getRight()));
}
}
for (AppliedMigration appliedRepeatableMigration : appliedRepeatableMigrations) {
if (!context.latestRepeatableRuns.containsKey(appliedRepeatableMigration.getDescription()) || (appliedRepeatableMigration.getInstalledRank() > context.latestRepeatableRuns.get(appliedRepeatableMigration.getDescription()))) {
context.latestRepeatableRuns.put(appliedRepeatableMigration.getDescription(), appliedRepeatableMigration.getInstalledRank());
}
}
Set<ResolvedMigration> pendingResolvedRepeatableMigrations = new HashSet<ResolvedMigration>(resolvedRepeatableMigrationsMap.values());
for (AppliedMigration appliedRepeatableMigration : appliedRepeatableMigrations) {
ResolvedMigration resolvedMigration = resolvedRepeatableMigrationsMap.get(appliedRepeatableMigration.getDescription());
int latestRank = context.latestRepeatableRuns.get(appliedRepeatableMigration.getDescription());
if (resolvedMigration != null && appliedRepeatableMigration.getInstalledRank() == latestRank && ObjectUtils.nullSafeEquals(appliedRepeatableMigration.getChecksum(), resolvedMigration.getChecksum())) {
pendingResolvedRepeatableMigrations.remove(resolvedMigration);
}
migrationInfos1.add(new MigrationInfoImpl(resolvedMigration, appliedRepeatableMigration, context, false));
}
for (ResolvedMigration pendingResolvedRepeatableMigration : pendingResolvedRepeatableMigrations) {
migrationInfos1.add(new MigrationInfoImpl(pendingResolvedRepeatableMigration, null, context, false));
}
Collections.sort(migrationInfos1);
migrationInfos = migrationInfos1;
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class CompositeMigrationResolver method checkForIncompatibilities.
/**
* Checks for incompatible migrations.
*
* @param migrations The migrations to check.
* @throws FlywayException when two different migration with the same version number are found.
*/
/* private -> for testing */
static void checkForIncompatibilities(List<ResolvedMigration> migrations) {
// check for more than one migration with same version
for (int i = 0; i < migrations.size() - 1; i++) {
ResolvedMigration current = migrations.get(i);
ResolvedMigration next = migrations.get(i + 1);
if (new ResolvedMigrationComparator().compare(current, next) == 0) {
if (current.getVersion() != null) {
throw new FlywayException(String.format("Found more than one migration with version %s\nOffenders:\n-> %s (%s)\n-> %s (%s)", current.getVersion(), current.getPhysicalLocation(), current.getType(), next.getPhysicalLocation(), next.getType()));
}
throw new FlywayException(String.format("Found more than one repeatable migration with description %s\nOffenders:\n-> %s (%s)\n-> %s (%s)", current.getDescription(), current.getPhysicalLocation(), current.getType(), next.getPhysicalLocation(), next.getType()));
}
}
}
use of org.flywaydb.core.api.resolver.ResolvedMigration in project flyway by flyway.
the class SqlMigrationResolver method resolveMigrations.
public List<ResolvedMigration> resolveMigrations() {
List<ResolvedMigration> migrations = new ArrayList<ResolvedMigration>();
scanForMigrations(migrations, configuration.getSqlMigrationPrefix(), configuration.getSqlMigrationSeparator(), configuration.getSqlMigrationSuffix());
scanForMigrations(migrations, configuration.getRepeatableSqlMigrationPrefix(), configuration.getSqlMigrationSeparator(), configuration.getSqlMigrationSuffix());
Collections.sort(migrations, new ResolvedMigrationComparator());
return migrations;
}
Aggregations