Skip to content

Commit

Permalink
Better handle the UnconfiguredDataSource case
Browse files Browse the repository at this point in the history
I wasn't exactly aware of this new development and it needs to be
handled a bit differently.

(cherry picked from commit 797162a)
  • Loading branch information
gsmet committed Sep 19, 2023
1 parent e64afbb commit d8be11a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javax.sql.DataSource;

import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.UnsatisfiedResolutionException;

import org.flywaydb.core.Flyway;
import org.flywaydb.core.FlywayExecutor;
Expand Down Expand Up @@ -67,7 +66,7 @@ public Function<SyntheticCreationalContext<FlywayContainer>, FlywayContainer> fl
public FlywayContainer apply(SyntheticCreationalContext<FlywayContainer> context) {
DataSource dataSource = context.getInjectedReference(DataSources.class).getDataSource(dataSourceName);
if (dataSource instanceof UnconfiguredDataSource) {
throw new UnsatisfiedResolutionException("No datasource present");
return new UnconfiguredDataSourceFlywayContainer(dataSourceName);
}

FlywayContainerProducer flywayProducer = context.getInjectedReference(FlywayContainerProducer.class);
Expand Down Expand Up @@ -106,6 +105,10 @@ public void doStartActions(String dataSourceName) {

FlywayContainer flywayContainer = flywayContainerInstanceHandle.get();

if (flywayContainer instanceof UnconfiguredDataSourceFlywayContainer) {
return;
}

if (flywayContainer.isCleanAtStart()) {
flywayContainer.getFlyway().clean();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.flyway.runtime;

import org.flywaydb.core.Flyway;

public class UnconfiguredDataSourceFlywayContainer extends FlywayContainer {

public UnconfiguredDataSourceFlywayContainer(String dataSourceName) {
super(null, false, false, false, false, false, dataSourceName, false, false);
}

@Override
public Flyway getFlyway() {
throw new UnsupportedOperationException(
"Cannot get a Flyway instance for unconfigured datasource " + getDataSourceName());
}
}

0 comments on commit d8be11a

Please sign in to comment.