Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flyway is not instantiated by using Named annotation fix #623 #634

Merged
merged 2 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions coverage-report/src/test/java/org/jooby/issues/Issue623.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create table v002 (
ID int not null,
NAME varchar(100) not null
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create table v010 (
ID int not null,
NAME varchar(100) not null
);
30 changes: 18 additions & 12 deletions jooby-flyway/src/main/java/org/jooby/flyway/Flywaydb.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Command> 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();
Expand All @@ -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<Command> commands(final Config config) {
private static Iterable<Command> commands(final Config config) {
Object value = config.getAnyRef("run");
List<String> commands = new ArrayList<>();
if (value instanceof List) {
Expand Down
2 changes: 1 addition & 1 deletion md/guides/guide.footer.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion md/guides/jdbi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}