Skip to content

Commit

Permalink
Properly determine classpath locations in Flyway
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand authored and gsmet committed Jul 16, 2020
1 parent 07a3a19 commit ebf9d59
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -103,7 +102,7 @@ void build(BuildProducer<FeatureBuildItem> featureProducer,

Collection<String> dataSourceNames = getDataSourceNames(jdbcDataSourceBuildItems);

List<String> applicationMigrations = discoverApplicationMigrations(getMigrationLocations(dataSourceNames));
Collection<String> applicationMigrations = discoverApplicationMigrations(getMigrationLocations(dataSourceNames));
recorder.setApplicationMigrationFiles(applicationMigrations);

Set<Class<?>> javaMigrationClasses = new HashSet<>();
Expand Down Expand Up @@ -196,15 +195,19 @@ private Collection<String> getMigrationLocations(Collection<String> dataSourceNa
return migrationLocations;
}

private List<String> discoverApplicationMigrations(Collection<String> locations) throws IOException, URISyntaxException {
private Collection<String> discoverApplicationMigrations(Collection<String> locations)
throws IOException, URISyntaxException {
try {
List<String> applicationMigrationResources = new ArrayList<>();
LinkedHashSet<String> applicationMigrationResources = new LinkedHashSet<>();
// Locations can be a comma separated list
for (String location : locations) {
// Strip any 'classpath:' protocol prefixes because they are assumed
// but not recognized by ClassLoader.getResources()
if (location != null && location.startsWith(CLASSPATH_APPLICATION_MIGRATIONS_PROTOCOL + ':')) {
location = location.substring(CLASSPATH_APPLICATION_MIGRATIONS_PROTOCOL.length() + 1);
if (location.startsWith("/")) {
location = location.substring(1);
}
}
Enumeration<URL> migrations = Thread.currentThread().getContextClassLoader().getResources(location);
while (migrations.hasMoreElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test_quarkus;DB_CLOSE_DE
quarkus.flyway.connect-retries=10
quarkus.flyway.schemas=TEST_SCHEMA
quarkus.flyway.table=flyway_quarkus_history
quarkus.flyway.locations=db/location1,classpath:db/location2
quarkus.flyway.locations=db/location1,classpath:db/location2,classpath:/db/location4
quarkus.flyway.sql-migration-prefix=V
quarkus.flyway.migrate-at-start=true
quarkus.flyway.placeholders.foo=bar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO TEST_SCHEMA.quarkus_table2(id, name)
VALUES (2, '1.0.2 QUARKED');
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FlywayFunctionalityTest {
@Test
@DisplayName("Migrates a schema correctly using integrated instance")
public void testFlywayQuarkusFunctionality() {
when().get("/flyway/migrate").then().body(is("1.0.1"));
when().get("/flyway/migrate").then().body(is("1.0.2"));
}

@Test
Expand Down

0 comments on commit ebf9d59

Please sign in to comment.