Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 0209d0c

Browse files
committed
Fix jooby-project#1124: Flyway placeholders - migration problem after jooby upgrade
1 parent e331eed commit 0209d0c

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

modules/jooby-flyway/src/main/java/org/jooby/flyway/Flywaydb.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@
210210
import com.typesafe.config.Config;
211211
import com.typesafe.config.ConfigFactory;
212212
import static com.typesafe.config.ConfigFactory.empty;
213-
import com.typesafe.config.ConfigValueType;
214213
import static java.util.Objects.requireNonNull;
215214
import org.flywaydb.core.Flyway;
216215
import org.jooby.Env;
@@ -361,7 +360,7 @@ public Flywaydb() {
361360
@Override
362361
public void configure(final Env env, final Config conf, final Binder binder) {
363362
Config $base = flyway(conf.getConfig("flyway"));
364-
Config $flyway = Try.apply(() -> conf.getConfig(name).withFallback($base))
363+
Config $flyway = Try.apply(() -> flyway(conf.getConfig(name)).withFallback($base))
365364
.orElse($base);
366365

367366
Flyway flyway = new Flyway();
@@ -377,15 +376,15 @@ public void configure(final Env env, final Config conf, final Binder binder) {
377376
env.serviceKey()
378377
.generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway));
379378
// commands:
380-
Iterable<Command> cmds = commands($flyway);
379+
Iterable<Command> cmds = commands(conf);
381380

382381
// eager initialization
383382
cmds.forEach(cmd -> cmd.run(flyway));
384383
}
385384

386-
private Config flyway(Config conf) {
385+
static Config flyway(Config conf) {
387386
Config flyway = conf.root().entrySet().stream()
388-
.filter(it -> it.getValue().valueType() != ConfigValueType.OBJECT)
387+
.filter(it -> isFlywayProperty(it.getKey()))
389388
.reduce(empty(), (seed, entry) -> seed.withValue(entry.getKey(), entry.getValue()),
390389
Config::withFallback);
391390
return flyway;
@@ -404,10 +403,7 @@ private static Properties props(final Config config) {
404403
if (value instanceof List) {
405404
value = ((List) value).stream().collect(Collectors.joining(","));
406405
}
407-
String propertyName = prop.getKey();
408-
if (isFlywayProperty(propertyName)) {
409-
props.setProperty("flyway." + prop.getKey(), value.toString());
410-
}
406+
props.setProperty("flyway." + prop.getKey(), value.toString());
411407
});
412408
return props;
413409
}
@@ -428,7 +424,7 @@ static boolean isFlywayProperty(String name) {
428424

429425
@SuppressWarnings("unchecked")
430426
private static Iterable<Command> commands(final Config config) {
431-
Object value = config.getAnyRef("run");
427+
Object value = config.getAnyRef("flyway.run");
432428
List<String> commands = new ArrayList<>();
433429
if (value instanceof List) {
434430
commands.addAll((List<? extends String>) value);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.jooby.flyway;
2+
3+
import static com.google.common.collect.ImmutableMap.of;
4+
import com.typesafe.config.ConfigFactory;
5+
import static org.junit.Assert.assertEquals;
6+
import org.junit.Test;
7+
8+
import java.util.Map;
9+
10+
public class Issue1124 {
11+
12+
@Test
13+
public void checkValidFlywayProperty() {
14+
Map conf = of("placeholders", of("tables", "foo"));
15+
Map<String, Object> expected = of("placeholders", of("tables", "foo"));
16+
assertEquals(expected, Flywaydb.flyway(ConfigFactory.parseMap(conf)).root().unwrapped());
17+
}
18+
19+
@Test
20+
public void filterResidualProperties() {
21+
Map conf = of("placeholders", of("tables", "foo"), "maxPoolSize", 1);
22+
Map<String, Object> expected = of("placeholders", of("tables", "foo"));
23+
assertEquals(expected, Flywaydb.flyway(ConfigFactory.parseMap(conf)).root().unwrapped());
24+
}
25+
}

0 commit comments

Comments
 (0)