Skip to content

Commit

Permalink
Merge pull request quarkusio#10732 from Teg79/master
Browse files Browse the repository at this point in the history
Added Flyway properties for placeholders prefix and suffix
  • Loading branch information
gastaldi authored Jul 15, 2020
2 parents 666fd68 + 4d88fb0 commit bb4eed6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public Flyway createFlyway(DataSource dataSource) {
}
configure.placeholders(flywayRuntimeConfig.placeholders);
configure.createSchemas(flywayRuntimeConfig.createSchemas);
if (flywayRuntimeConfig.placeholderPrefix.isPresent()) {
configure.placeholderPrefix(flywayRuntimeConfig.placeholderPrefix.get());
}
if (flywayRuntimeConfig.placeholderSuffix.isPresent()) {
configure.placeholderSuffix(flywayRuntimeConfig.placeholderSuffix.get());
}

/*
* Ensure that no classpath scanning takes place by setting the ClassProvider and the ResourceProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ public static final FlywayDataSourceRuntimeConfig defaultConfig() {
@ConfigItem(defaultValue = "true")
public boolean createSchemas;

/**
* Prefix of every placeholder (default: ${ )
*/
@ConfigItem
public Optional<String> placeholderPrefix = Optional.empty();

/**
* Suffix of every placeholder (default: } )
*/
@ConfigItem
public Optional<String> placeholderSuffix = Optional.empty();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Objects;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -26,6 +27,9 @@ public class FlywayFunctionalityResource {
@FlywayDataSource("second-datasource")
Flyway flyway2;

@Inject
EntityManager entityManager;

@GET
@Path("migrate")
public String doMigrateAuto() {
Expand All @@ -35,6 +39,13 @@ public String doMigrateAuto() {
return version.toString();
}

@GET
@Path("title")
public String returnTitle() {
return entityManager.createQuery("select a from AppEntity a where a.id = 1", AppEntity.class)
.getSingleResult().getName();
}

@GET
@Path("multiple-flyway-migration")
public String doMigrationOfSecondDataSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ quarkus.flyway.locations=db/location1,classpath:db/location2,classpath:/db/locat
quarkus.flyway.sql-migration-prefix=V
quarkus.flyway.migrate-at-start=true
quarkus.flyway.placeholders.foo=bar
quarkus.flyway.placeholders.title=REPLACED
quarkus.flyway.placeholder-prefix=#[
quarkus.flyway.placeholder-suffix=]

quarkus.hibernate-orm.database.generation=validate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CREATE TABLE TEST_SCHEMA.quarkus_table2
name VARCHAR(20)
);
INSERT INTO TEST_SCHEMA.quarkus_table2(id, name)
VALUES (1, '1.0.1 QUARKED');
VALUES (1, '1.0.1 #[title]');
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CREATE TABLE TEST_SCHEMA.quarkus
name VARCHAR(20)
);
INSERT INTO TEST_SCHEMA.quarkus(id, name)
VALUES (1, '${foo}');
VALUES (1, '#[foo]');
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ public void testPlaceholders() {
public void testCreateSchemasDefaultIsTrue() {
when().get("/flyway/create-schemas").then().body(is("true"));
}

@Test
@DisplayName("Verify placeholder replacement")
public void testPlaceholdersPrefixSuffix() {
when().get("/flyway/title").then().body(is("1.0.1 REPLACED"));
}

}

0 comments on commit bb4eed6

Please sign in to comment.