use of org.flywaydb.core.internal.resolver.ResolvedMigrationImpl in project flyway by flyway.
the class MigrationInfoDumperSmallTest method createAvailableMigration.
/**
* Creates a new available migration with this version.
*
* @param version The version of the migration.
* @return The available migration.
*/
private ResolvedMigration createAvailableMigration(String version) {
ResolvedMigrationImpl migration = new ResolvedMigrationImpl();
migration.setVersion(MigrationVersion.fromVersion(version));
migration.setDescription("abc very very very very very very very very very very long");
migration.setScript("x");
migration.setType(MigrationType.SQL);
return migration;
}
use of org.flywaydb.core.internal.resolver.ResolvedMigrationImpl 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.internal.resolver.ResolvedMigrationImpl in project ArachneCentralAPI by OHDSI.
the class ApplicationContextAwareSpringJdbcMigrationResolver method extractMigrationInfo.
/**
* Extracts the migration info from this migration.
*
* @param springJdbcMigration The migration to analyse.
* @return The migration info.
*/
/* private -> testing */
ResolvedMigrationImpl extractMigrationInfo(ApplicationContextAwareSpringMigration springJdbcMigration) {
Integer checksum = null;
if (springJdbcMigration instanceof MigrationChecksumProvider) {
MigrationChecksumProvider checksumProvider = (MigrationChecksumProvider) springJdbcMigration;
checksum = checksumProvider.getChecksum();
}
MigrationVersion version;
String description;
if (springJdbcMigration instanceof MigrationInfoProvider) {
MigrationInfoProvider infoProvider = (MigrationInfoProvider) springJdbcMigration;
version = infoProvider.getVersion();
description = infoProvider.getDescription();
if (!StringUtils.hasText(description)) {
throw new FlywayException("Missing description for migration " + version);
}
} else {
String shortName = ClassUtils.getShortName(springJdbcMigration.getClass());
String prefix;
boolean repeatable = shortName.startsWith("R");
if (shortName.startsWith("V") || repeatable) {
prefix = shortName.substring(0, 1);
} else {
throw new FlywayException("Invalid Spring migration class name: " + springJdbcMigration.getClass().getName() + " => ensure it starts with V or R," + " or implement org.flywaydb.core.api.migration.MigrationInfoProvider for non-default naming");
}
Pair<MigrationVersion, String> info = MigrationInfoHelper.extractVersionAndDescription(shortName, prefix, "__", "", repeatable);
version = info.getLeft();
description = info.getRight();
}
ResolvedMigrationImpl resolvedMigration = new ResolvedMigrationImpl();
resolvedMigration.setVersion(version);
resolvedMigration.setDescription(description);
resolvedMigration.setScript(springJdbcMigration.getClass().getName());
resolvedMigration.setChecksum(checksum);
resolvedMigration.setType(MigrationType.SPRING_JDBC);
return resolvedMigration;
}
use of org.flywaydb.core.internal.resolver.ResolvedMigrationImpl in project flyway by flyway.
the class MigrationInfoImplSmallTest method createResolvedMigration.
/**
* Creates a new resolved repeatable migration with this description.
*
* @param description The description of the migration.
* @return The resolved migration.
*/
private ResolvedMigration createResolvedMigration(String version, String description) {
ResolvedMigrationImpl migration = new ResolvedMigrationImpl();
migration.setVersion(version == null ? null : MigrationVersion.fromVersion(version));
migration.setDescription(description);
migration.setScript(description);
migration.setType(MigrationType.SQL);
return migration;
}
use of org.flywaydb.core.internal.resolver.ResolvedMigrationImpl in project flyway by flyway.
the class MigrationInfoImplSmallTest method validate.
@Test
public void validate() {
MigrationVersion version = MigrationVersion.fromVersion("1");
String description = "test";
MigrationType type = MigrationType.SQL;
ResolvedMigrationImpl resolvedMigration = new ResolvedMigrationImpl();
resolvedMigration.setVersion(version);
resolvedMigration.setDescription(description);
resolvedMigration.setType(type);
resolvedMigration.setChecksum(456);
AppliedMigration appliedMigration = new AppliedMigration(1, version, description, type, null, 123, new Date(), "abc", 0, true);
MigrationInfoImpl migrationInfo = new MigrationInfoImpl(resolvedMigration, appliedMigration, new MigrationInfoContext(), false);
String message = migrationInfo.validate();
assertTrue(message.contains("123"));
assertTrue(message.contains("456"));
}
Aggregations