org.flywaydb.core.api.resolver.ResolvedMigration Java Examples
The following examples show how to use
org.flywaydb.core.api.resolver.ResolvedMigration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptimizedFlywayTestExecutionListener.java From embedded-database-spring-test with Apache License 2.0 | 5 votes |
protected static MigrationVersion findFirstVersion(Flyway flyway, String... locations) throws ClassNotFoundException { Collection<ResolvedMigration> migrations = resolveMigrations(flyway, locations); return migrations.stream() .filter(migration -> migration.getVersion() != null) .findFirst() .map(ResolvedMigration::getVersion) .orElse(MigrationVersion.EMPTY); }
Example #2
Source File: OptimizedFlywayTestExecutionListener.java From embedded-database-spring-test with Apache License 2.0 | 5 votes |
protected static MigrationVersion findLastVersion(Flyway flyway, String... locations) throws ClassNotFoundException { Collection<ResolvedMigration> migrations = resolveMigrations(flyway, locations); return migrations.stream() .filter(migration -> migration.getVersion() != null) .reduce((first, second) -> second) // finds last item .map(ResolvedMigration::getVersion) .orElse(MigrationVersion.EMPTY); }
Example #3
Source File: OptimizedFlywayTestExecutionListener.java From embedded-database-spring-test with Apache License 2.0 | 5 votes |
protected static Collection<ResolvedMigration> resolveMigrations(Flyway flyway, String... locations) throws ClassNotFoundException { MigrationResolver resolver = createMigrationResolver(flyway, locations); if (flywayVersion >= 52) { Object configInstance = getField(flyway, "configuration"); Class<?> contextType = ClassUtils.forName("org.flywaydb.core.api.resolver.Context", classLoader); Object contextInstance = ProxyFactory.getProxy(contextType, (MethodInterceptor) invocation -> "getConfiguration".equals(invocation.getMethod().getName()) ? configInstance : invocation.proceed()); return invokeMethod(resolver, "resolveMigrations", contextInstance); } else { return resolver.resolveMigrations(); } }
Example #4
Source File: ShellMigrationResolver.java From registry with Apache License 2.0 | 5 votes |
public List<ResolvedMigration> resolveMigrations() { List<ResolvedMigration> migrations = new ArrayList<ResolvedMigration>(); Resource[] resources = scanner.scanForResources(location, shellMigrationPrefix, new String[] {shellMigrationSuffix}); for (Resource resource : resources) { ResolvedMigrationImpl resolvedMigration = extractMigrationInfo(resource); resolvedMigration.setPhysicalLocation(resource.getLocationOnDisk()); resolvedMigration.setExecutor(new ShellMigrationExecutor(resource)); migrations.add(resolvedMigration); } Collections.sort(migrations, new ResolvedMigrationComparator()); return migrations; }
Example #5
Source File: CustomSqlMigrationResolver.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public Collection<ResolvedMigration> resolveMigrations() { try { return resolveSqlMigrations(); } catch (IOException | SQLException x) { throw new RuntimeException(x.getLocalizedMessage(), x); } }
Example #6
Source File: CustomSqlMigrationResolver.java From che with Eclipse Public License 2.0 | 4 votes |
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)); if (migrations.put(migration.getVersion(), migration) != null) { throw new FlywayException("Two migrations with the same version detected"); } } return new ArrayList<>(migrations.values()); }