diff --git a/coverage-report/src/test/java/org/jooby/issues/Issue623.java b/coverage-report/src/test/java/org/jooby/issues/Issue623.java new file mode 100644 index 0000000000..6ee8651888 --- /dev/null +++ b/coverage-report/src/test/java/org/jooby/issues/Issue623.java @@ -0,0 +1,42 @@ +package org.jooby.issues; + +import java.util.Arrays; + +import org.flywaydb.core.Flyway; +import org.jooby.flyway.Flywaydb; +import org.jooby.test.ServerFeature; +import org.junit.Test; + +import com.typesafe.config.ConfigFactory; +import com.typesafe.config.ConfigValueFactory; + +public class Issue623 extends ServerFeature { + + { + use(ConfigFactory.empty() + .withValue("flyway.db1.url", + ConfigValueFactory.fromAnyRef("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1")) + .withValue("flyway.db1.locations", ConfigValueFactory + .fromAnyRef(Arrays.asList("i623/fway1"))) + .withValue("flyway.db2.url", + ConfigValueFactory.fromAnyRef("jdbc:h2:mem:db2;DB_CLOSE_DELAY=-1")) + .withValue("flyway.db2.locations", ConfigValueFactory + .fromAnyRef(Arrays.asList("i623/fway2")))); + + use(new Flywaydb("flyway.db1")); + use(new Flywaydb("flyway.db2")); + + get("/623", req -> req.require(req.param("name").value(), Flyway.class).info().current() + .getDescription()); + } + + @Test + public void bootstratp2dbs() throws Exception { + request() + .get("/623?name=flyway.db1") + .expect("fway1"); + request() + .get("/623?name=flyway.db2") + .expect("fway2"); + } +} diff --git a/coverage-report/src/test/resources/i623/fway1/v0.0.2_fway1.sql b/coverage-report/src/test/resources/i623/fway1/v0.0.2_fway1.sql new file mode 100644 index 0000000000..51d3637e66 --- /dev/null +++ b/coverage-report/src/test/resources/i623/fway1/v0.0.2_fway1.sql @@ -0,0 +1,4 @@ +create table v002 ( + ID int not null, + NAME varchar(100) not null +); \ No newline at end of file diff --git a/coverage-report/src/test/resources/i623/fway2/v0.1.0_fway2.sql b/coverage-report/src/test/resources/i623/fway2/v0.1.0_fway2.sql new file mode 100644 index 0000000000..aab8954d80 --- /dev/null +++ b/coverage-report/src/test/resources/i623/fway2/v0.1.0_fway2.sql @@ -0,0 +1,4 @@ +create table v010 ( + ID int not null, + NAME varchar(100) not null +); \ No newline at end of file diff --git a/jooby-flyway/src/main/java/org/jooby/flyway/Flywaydb.java b/jooby-flyway/src/main/java/org/jooby/flyway/Flywaydb.java index 85f0210f39..ed3cc15405 100644 --- a/jooby-flyway/src/main/java/org/jooby/flyway/Flywaydb.java +++ b/jooby-flyway/src/main/java/org/jooby/flyway/Flywaydb.java @@ -173,18 +173,29 @@ public Flywaydb() { } @Override - public void configure(final Env env, final Config config, final Binder binder) { - Config $flyway = config.getConfig(name) - .withFallback(config.getConfig("flyway")); + public void configure(final Env env, final Config conf, final Binder binder) { + Config $flyway = conf.getConfig(name) + .withFallback(conf.getConfig("flyway")); Flyway flyway = new Flyway(); flyway.configure(props($flyway)); - commands($flyway).forEach(cmd -> cmd.run(flyway)); - binder.bind(Flyway.class).toInstance(flyway); + // bind + env.serviceKey() + .generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway)); + // run + Iterable cmds = commands($flyway); + env.onStart(() -> { + cmds.forEach(cmd -> cmd.run(flyway)); + }); + } + + @Override + public Config config() { + return ConfigFactory.parseResources(getClass(), "flyway.conf"); } @SuppressWarnings({"unchecked", "rawtypes" }) - private Properties props(final Config config) { + private static Properties props(final Config config) { Properties props = new Properties(); config.withoutPath("run").entrySet().forEach(prop -> { Object value = prop.getValue().unwrapped(); @@ -196,13 +207,8 @@ private Properties props(final Config config) { return props; } - @Override - public Config config() { - return ConfigFactory.parseResources(getClass(), "flyway.conf"); - } - @SuppressWarnings("unchecked") - private Iterable commands(final Config config) { + private static Iterable commands(final Config config) { Object value = config.getAnyRef("run"); List commands = new ArrayList<>(); if (value instanceof List) { diff --git a/md/guides/guide.footer.md b/md/guides/guide.footer.md index 1fd04f2db6..d4d39398e8 100644 --- a/md/guides/guide.footer.md +++ b/md/guides/guide.footer.md @@ -1,6 +1,6 @@ # source code -* Complete source code available at: [jooby-guides/{{guide}}]({{gh-guides}}/{{guide}}) +* Complete source code available at: [jooby-project/{{guide}}]({{gh-guides}}/{{guide}}) # help and support diff --git a/md/guides/jdbi.md b/md/guides/jdbi.md index fd339e52cf..384d23eb44 100644 --- a/md/guides/jdbi.md +++ b/md/guides/jdbi.md @@ -350,4 +350,4 @@ As you already see, building an API that saves data in a **database** is very si The {{modlink "jdbi"}} module makes perfect sense if you want to have full control on your SQL queries, or if you don't like **ORM** tools too. -{{guides/guide.footer.md}} +{{> guides/guide.footer}}