org.flywaydb.core.internal.resolver.ResolvedMigrationImpl Java Examples
The following examples show how to use
org.flywaydb.core.internal.resolver.ResolvedMigrationImpl.
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: ShellMigrationResolver.java From registry with Apache License 2.0 | 6 votes |
/** * Extracts the migration info for this resource. * * @param resource The resource to analyse. * @return The migration info. */ private ResolvedMigrationImpl extractMigrationInfo(Resource resource) { ResolvedMigrationImpl migration = new ResolvedMigrationImpl(); Pair<MigrationVersion, String> info = MigrationInfoHelper.extractVersionAndDescription(resource.getFilename(), shellMigrationPrefix, shellMigrationSeparator, new String [] {shellMigrationSuffix}, false); migration.setVersion(info.getLeft()); migration.setDescription(info.getRight()); migration.setScript(extractScriptName(resource)); byte [] migrationScriptAsBytes = null; try { migrationScriptAsBytes = IOUtils.toByteArray(new FileInputStream(resource.getLocation())); } catch (Exception e) { throw new ShellMigrationException(String.format("Failed to read the migration script : %s", resource.getLocation()), e); } migration.setChecksum(calculateChecksum(migrationScriptAsBytes)); migration.setType(MigrationType.CUSTOM); return migration; }
Example #2
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 #3
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()); }