/** * 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; }
/** * 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; }
/** * {@inheritDoc} */ @Override public Collection<ResolvedMigration> resolveMigrations() { List<ResolvedMigration> resolvedMigrations = Lists.newArrayList(); ScriptInfo info = migration.generate(); if (info != null) { ResolvedMigrationImpl migration = new ResolvedMigrationImpl(); migration.setVersion(MigrationVersion.fromVersion(info.getRevision())); migration.setDescription(info.getDescription()); migration.setScript(info.getRevision() + "__" + toUnderScore(info.getDescription()) + ".sql"); migration.setChecksum(calculateChecksum("-- " + info.getRevision() + "\r\n" + info.getApplyDdl())); migration.setType(MigrationType.SQL); migration.setExecutor(new SqlMigrationExecutor(info)); resolvedMigrations.add(migration); } return resolvedMigrations; }