@Test public void shouldResolveNextMigration() throws Exception { File migrationsDir = tempFolder.newFolder(); migrationsDir.toPath().resolve("v1__jpa2ddl.sql").toFile().createNewFile(); migrationsDir.toPath().resolve("v2__my_description.sql").toFile().createNewFile(); File file = FileResolver.resolveNextMigrationFile(migrationsDir); assertThat(file.toPath()).isEqualTo(migrationsDir.toPath().resolve("v3__jpa2ddl.sql")); }
static File resolveNextMigrationFile(File migrationDir) { Optional<Path> lastFile = resolveExistingMigrations(migrationDir, true, false) .stream() .findFirst(); Long fileIndex = lastFile.map((Path input) -> FILENAME_PATTERN.matcher(input.getFileName().toString())) .map(matcher -> { if (matcher.find()) { return Long.valueOf(matcher.group(1)); } else { return 0L; } }).orElse(0L); return migrationDir.toPath().resolve("v" + ++fileIndex + "__jpa2ddl.sql").toFile(); }
FileResolver { static File resolveNextMigrationFile(File migrationDir) { Optional<Path> lastFile = resolveExistingMigrations(migrationDir, true, false) .stream() .findFirst(); Long fileIndex = lastFile.map((Path input) -> FILENAME_PATTERN.matcher(input.getFileName().toString())) .map(matcher -> { if (matcher.find()) { return Long.valueOf(matcher.group(1)); } else { return 0L; } }).orElse(0L); return migrationDir.toPath().resolve("v" + ++fileIndex + "__jpa2ddl.sql").toFile(); } }
FileResolver { static File resolveNextMigrationFile(File migrationDir) { Optional<Path> lastFile = resolveExistingMigrations(migrationDir, true, false) .stream() .findFirst(); Long fileIndex = lastFile.map((Path input) -> FILENAME_PATTERN.matcher(input.getFileName().toString())) .map(matcher -> { if (matcher.find()) { return Long.valueOf(matcher.group(1)); } else { return 0L; } }).orElse(0L); return migrationDir.toPath().resolve("v" + ++fileIndex + "__jpa2ddl.sql").toFile(); }  }
FileResolver { static File resolveNextMigrationFile(File migrationDir) { Optional<Path> lastFile = resolveExistingMigrations(migrationDir, true, false) .stream() .findFirst(); Long fileIndex = lastFile.map((Path input) -> FILENAME_PATTERN.matcher(input.getFileName().toString())) .map(matcher -> { if (matcher.find()) { return Long.valueOf(matcher.group(1)); } else { return 0L; } }).orElse(0L); return migrationDir.toPath().resolve("v" + ++fileIndex + "__jpa2ddl.sql").toFile(); }   }
FileResolver { static File resolveNextMigrationFile(File migrationDir) { Optional<Path> lastFile = resolveExistingMigrations(migrationDir, true, false) .stream() .findFirst(); Long fileIndex = lastFile.map((Path input) -> FILENAME_PATTERN.matcher(input.getFileName().toString())) .map(matcher -> { if (matcher.find()) { return Long.valueOf(matcher.group(1)); } else { return 0L; } }).orElse(0L); return migrationDir.toPath().resolve("v" + ++fileIndex + "__jpa2ddl.sql").toFile(); }    }