-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Unable to configure flyway.datasources.*.ignore-migration-patter…
…ns (#330) * Fix for issue #309 Unable to configure flyway.datasources.*.ignore-migration-patterns * Fix for issue #309 Unable to configure flyway.datasources.*.ignore-migration-patterns * Check value ends up in the FluentConfig Co-authored-by: nenadvico <[email protected]>
- Loading branch information
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
flyway/src/main/java/io/micronaut/flyway/ValidatePatternTypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.flyway; | ||
|
||
import io.micronaut.core.convert.ConversionContext; | ||
import io.micronaut.core.convert.TypeConverter; | ||
import jakarta.inject.Singleton; | ||
import org.flywaydb.core.api.pattern.ValidatePattern; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Converts String's to Flyway ValidatePattern required for reading ignore-migration-patterns parameter. | ||
* | ||
* @author Nenad Vico | ||
* @see org.flywaydb.core.api.pattern.ValidatePattern | ||
* @since 5.4.1 | ||
*/ | ||
@Singleton | ||
public class ValidatePatternTypeConverter implements TypeConverter<String, ValidatePattern> { | ||
|
||
@Override | ||
public Optional<ValidatePattern> convert(String pattern, | ||
Class<ValidatePattern> targetType, | ||
ConversionContext context) { | ||
if (pattern == null || pattern.trim().length() == 0) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(ValidatePattern.fromPattern(pattern)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
flyway/src/test/groovy/io/micronaut/flyway/ValidatePatternTypeConverterSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package io.micronaut.flyway | ||
|
||
import org.flywaydb.core.api.ErrorCode | ||
import org.flywaydb.core.api.FlywayException | ||
import org.flywaydb.core.api.MigrationState | ||
import org.flywaydb.core.api.pattern.ValidatePattern | ||
import org.flywaydb.core.internal.license.FlywayTeamsUpgradeRequiredException | ||
import spock.lang.Specification | ||
|
||
/** | ||
* @author Nenad Vico | ||
*/ | ||
class ValidatePatternTypeConverterSpec extends Specification { | ||
|
||
|
||
void "test empty string conversion"() { | ||
given: | ||
ValidatePatternTypeConverter validatePatternTypeConverter = new ValidatePatternTypeConverter() | ||
|
||
expect: | ||
!validatePatternTypeConverter.convert("", ValidatePattern.class).isPresent() | ||
} | ||
|
||
void "test wrong string conversion"() { | ||
given: | ||
ValidatePatternTypeConverter validatePatternTypeConverter = new ValidatePatternTypeConverter() | ||
|
||
when: | ||
validatePatternTypeConverter.convert("junk", ValidatePattern.class) | ||
|
||
then: | ||
def e = thrown(FlywayException) | ||
e.errorCode == ErrorCode.ERROR | ||
e.message == 'Invalid pattern \'junk\'. Pattern must be of the form <migration_type>:<migration_state> See https://rd.gt/37m4hXD for full details' | ||
} | ||
|
||
void "test future string conversion"() { | ||
given: | ||
ValidatePatternTypeConverter validatePatternTypeConverter = new ValidatePatternTypeConverter() | ||
|
||
expect: | ||
validatePatternTypeConverter.convert("*:future", ValidatePattern.class).get() | ||
.matchesMigration(false, MigrationState.FUTURE_SUCCESS) | ||
} | ||
|
||
void "test repeatable string conversion"() { | ||
given: | ||
ValidatePatternTypeConverter validatePatternTypeConverter = new ValidatePatternTypeConverter() | ||
|
||
when: | ||
validatePatternTypeConverter.convert("repeatable:*", ValidatePattern.class) | ||
|
||
then: | ||
def e = thrown(FlywayTeamsUpgradeRequiredException) | ||
e.errorCode == ErrorCode.ERROR | ||
e.message == 'Flyway Teams Edition upgrade required: ignoreMigrationPattern with type \'repeatable\' is not supported by Flyway Community Edition\n' + | ||
'Try Flyway Teams Edition for free: https://rd.gt/2VzHpkY' | ||
} | ||
|
||
void "test versioned string conversion"() { | ||
given: | ||
ValidatePatternTypeConverter validatePatternTypeConverter = new ValidatePatternTypeConverter() | ||
|
||
when: | ||
validatePatternTypeConverter.convert("versioned:missing", ValidatePattern.class) | ||
|
||
then: | ||
def e = thrown(FlywayTeamsUpgradeRequiredException) | ||
e.errorCode == ErrorCode.ERROR | ||
e.message == 'Flyway Teams Edition upgrade required: ignoreMigrationPattern with type \'versioned\' is not supported by Flyway Community Edition\n' + | ||
'Try Flyway Teams Edition for free: https://rd.gt/2VzHpkY' | ||
} | ||
|
||
void "test missing string conversion"() { | ||
given: | ||
ValidatePatternTypeConverter validatePatternTypeConverter = new ValidatePatternTypeConverter() | ||
|
||
expect: | ||
validatePatternTypeConverter.convert("*:missing", ValidatePattern.class).get() | ||
.matchesMigration(false, MigrationState.MISSING_SUCCESS) | ||
} | ||
|
||
} |