我想知道有没有办法在运行时使用Flyway的Callback
方法排除某些迁移。
我已经在其中做了一些工作,但我想在其说明中排除一些包含 dev 的迁移。
谢谢!
编辑:将我的简单更改添加到迁移解析程序
@Override
public Collection<ResolvedMigration> resolveMigrations() {
assert flyway != null;
assert flyway.getLocations() != null;
assert flyway.getLocations().length > 0;
List<ResolvedMigration> migrations = Lists.newArrayList();
for (String stringLocation : flyway.getLocations()) {
Location location = new Location(stringLocation);
Scanner scanner = new Scanner(ClassLoader.getSystemClassLoader());
Resource[] resources = scanner.scanForResources(location,
flyway.getSqlMigrationPrefix(),
flyway.getSqlMigrationSuffix());
for (Resource resource : resources) {
if (!resource.getFilename().contains("_dev")) {
ResolvedMigrationImpl resolvedMigration = extractMigrationInfo(location, resource);
resolvedMigration.setPhysicalLocation(resource.getLocationOnDisk());
resolvedMigration.setExecutor(new SqlMigrationExecutor(new PostgreSQLDbSupport(flywayConnection),
resource,
new PlaceholderReplacer(flyway.getPlaceholders(),
flyway.getPlaceholderPrefix(),
flyway.getPlaceholderSuffix()),
flyway.getEncoding()));
migrations.add(resolvedMigration);
}
}
Collections.sort(migrations, new ResolvedMigrationComparator());
}
return migrations;
}