I'm working on setting up Flyway in my quarkus app that already has appropriate database setup, works fine but does the hand-done db setup (initdb()) method to setup its database.
I currently test using a postgresql testcontainer instance to test against, and set it up in the following way:
@Override
public Map<String, String> start() {
log.info("STARTING test lifecycle resources.");
Map<String, String> configOverride = new HashMap<>();
if(MYSQL_CONTAINER == null || !MYSQL_CONTAINER.isRunning()){
PostgreSQLContainerProvider provider = new PostgreSQLContainerProvider();
MYSQL_CONTAINER = provider.newInstance();
MYSQL_CONTAINER.withDatabaseName("client-demo");
MYSQL_CONTAINER.start();
}
configOverride.put("quarkus.datasource.db-kind", "postgresql");
configOverride.put("quarkus.datasource.username", MYSQL_CONTAINER.getUsername());
configOverride.put("quarkus.datasource.password", MYSQL_CONTAINER.getPassword());
// replaceFirst required to connect; invalidUri exception thrown otherwise
configOverride.put("quarkus.datasource.reactive.url", MYSQL_CONTAINER.getJdbcUrl().replaceFirst("jdbc:", ""));
log.info("Config overrides: {}", configOverride);
return configOverride;
}
This has worked fine thusfar, and the test code can appropriately interact with the database as expected.
However, when I try to add Flyway to the equation, it seems that Flyway can't connect to the database:
2022-01-25 14:23:03,005 INFO [org.acm.cus.dem.uti.TestResourceLifecycleManager] (pool-4-thread-1) Config overrides: {quarkus.datasource.password=test, quarkus.datasource.db-kind=postgresql, quarkus.datasource.reactive.url=postgresql://localhost:49352/client-demo?loggerLevel=OFF, quarkus.datasource.username=test}
2022-01-25 14:23:03,695 WARN [io.agr.pool] (agroal-11) Datasource '<default>': FATAL: password authentication failed for user "test"
2022-01-25 14:23:03,721 INFO [org.acm.cus.dem.uti.TestResourceLifecycleManager] (main) STOPPING test lifecycle resources.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 15.251 s <<< FAILURE! - in org.acme.cust.demo.CucumberTest
[ERROR] org.acme.cust.demo.CucumberTest.getTests Time elapsed: 15.238 s <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException:
Unable to obtain connection from database: FATAL: password authentication failed for user "test"
Any ideas?
CodePudding user response:
In your config you mention a reactive database connection. But Flyway still needs the „old“ jdbc connection. So you probably have to configure both, if you still want to use the db the reactive way.
