Skip to content

Commit

Permalink
Enhance and clarify configuration properties map (#480)
Browse files Browse the repository at this point in the history
The `properties` setter in `FlywayConfigurationProperties` is enhanced
to convert property keys to camel case as required by Flyway's
`FluentConfiguration` builder class.

Documentation is clarified and links to the Flyway documentation are
updated to use permalinks.
  • Loading branch information
jeremyg484 authored Dec 15, 2023
1 parent 2f95b65 commit b4cf749
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.micronaut.context.annotation.EachProperty;
import io.micronaut.context.annotation.Parameter;
import io.micronaut.core.convert.format.MapFormat;
import io.micronaut.core.naming.conventions.StringConvention;
import io.micronaut.core.util.StringUtils;
import io.micronaut.core.util.Toggleable;
import org.flywaydb.core.api.configuration.FluentConfiguration;
Expand Down Expand Up @@ -193,20 +194,19 @@ public FluentConfiguration getFluentConfiguration() {
}

/**
* @see <a href="https://documentation.red-gate.com/fd/parameters-184127474.html">Flyway parameters</a>.
* @see <a href="https://documentation.red-gate.com/fd/flyway-cli-and-api/configuration/parameters">Flyway parameters</a>.
* Sets the extra flyway parameters to be passed to {@link FluentConfiguration#configuration(Map)}.
* WARNING: This may override any existing configurations
* WARNING: This will override any existing configuration properties with the same names.
*
* @param properties The properties to be set
*/
public void setProperties(@MapFormat(transformation = MapFormat.MapTransformation.FLAT) Map<String, String> properties) {
public void setProperties(@MapFormat(transformation = MapFormat.MapTransformation.FLAT, keyFormat = StringConvention.CAMEL_CASE) Map<String, String> properties) {
this.properties = properties;
}

/**
* @see <a href="https://documentation.red-gate.com/fd/parameters-184127474.html">Flyway parameters</a>.
* @see <a href="https://documentation.red-gate.com/fd/flyway-cli-and-api/configuration/parameters">Flyway parameters</a>.
* Gets the extra flyway parameters to be passed to {@link FluentConfiguration#configuration(Map)}.
* WARNING: This may override any existing configurations
*
* @return The extra custom properties
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.micronaut.flyway


import io.micronaut.context.exceptions.NoSuchBeanException
import io.micronaut.inject.qualifiers.Qualifiers
import org.flywaydb.core.Flyway
Expand Down Expand Up @@ -87,6 +88,28 @@ class FlywayConfigurationPropertiesEnabledSpec extends AbstractFlywaySpec {
applicationContext.getConversionService().canConvert(String.class, ValidatePattern.class)
}

void 'if flyway configuration then camel case configuration properties in the properties map can be set successfully'() {
given:
run('spec.name' : FlywayConfigurationPropertiesEnabledSpec.simpleName,
'flyway.datasources.movies.enabled' : true,
'flyway.datasources.movies.properties.flyway.baselineVersion' : "0.0",
'datasources.movies.url' : 'jdbc:h2:mem:flyway2Db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE',
'datasources.movies.username' : DS_USERNAME,
'datasources.movies.password' : DS_PASSWORD,
'datasources.movies.driverClassName': DS_DRIVER)

when:
applicationContext.getBean(DataSource, Qualifiers.byName('movies'))
def configuration = applicationContext.getBean(FlywayConfigurationProperties, Qualifiers.byName('movies'))
applicationContext.getBean(Flyway, Qualifiers.byName('movies'))

then:
noExceptionThrown()

and:
configuration.fluentConfiguration.baselineVersion.version == "0.0"
}

void 'if flyway is disabled, then FlywayConfigurationProperties bean is created but Flyway bean is not'() {
given:
run('spec.name' : FlywayConfigurationPropertiesEnabledSpec.simpleName,
Expand Down
6 changes: 4 additions & 2 deletions src/main/docs/guide/configuration/additionalConfig.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ NOTE: By default Micronaut will configure Flyway to use the datasources defined
you want to use a different datasource you need to define the properties `+flyway.datasources.*.url+`, `+flyway.datasources.*.user+`
and `+flyway.datasources.*.password+`.

=== Flyway Parameters
=== Flyway Configuration Parameters

You can setup https://documentation.red-gate.com/fd/parameters-184127474.html[flyway parameters]. For example, you can setup https://documentation.red-gate.com/fd/postgresql-transactional-lock-184127530.html[PostgreSQL Transactional Lock]:
You can set https://documentation.red-gate.com/fd/flyway-cli-and-api/configuration/parameters[flyway configuration parameters]. For example, you can setup https://documentation.red-gate.com/fd/flyway-cli-and-api/configuration/parameters/flyway/postgresql-transactional-lock[PostgreSQL Transactional Lock]:

[configuration]
----
include::{flywaytests}/groovy/io/micronaut/flyway/postgresql/TransactionLockSpec.groovy[tag=yaml,indent=0]
----

Note that setting configuration this way will override any matching properties set via the known configuration keys in the tables above.

0 comments on commit b4cf749

Please sign in to comment.