简体   繁体   中英

flyway how to use placeholder in insert query inside SQL file

Application.properties

TM_ESCALATION_QUALIFICATION=SHIFT_LEADER

Application.java

@Value( "${TM_ESCALATION_QUALIFICATION}" )
String escalationQualification;

@Bean
InitializingBean printConfigurations(DataSource datasource) {
    return () -> {
            Flyway flyway = new Flyway();
            flyway.setDataSource(datasource);
            flyway.getPlaceholders().put( "ESCALATION_QUALIFICATION", escalationQualification );    
            flyway.migrate();
    };
}

SQL file

insert into tm_qualification (ID, NAME, DELETABLE) values (sys_guid(), ${ESCALATION_QUALIFICATION}, 0); 

Above is working when I use file with default extension, but getting below error when I make file as .sql extension.

ERROR

org.flywaydb.core.api.FlywayException: No value provided for placeholder expressions: ${ESCALATION_QUALIFICATION}.  Check your configuration!
    at org.flywaydb.core.internal.util.PlaceholderReplacer.checkForUnmatchedPlaceholderExpression(PlaceholderReplacer.java:101)
    at org.flywaydb.core.internal.util.PlaceholderReplacer.replacePlaceholders(PlaceholderReplacer.java:78)
    at org.flywaydb.core.internal.dbsupport.SqlScript.<init>(SqlScript.java:79)....

From the web, suggestions are to use

flyway.placeholderReplacement=false

Which only worked after upgrading to > flyway 4.0.3 (spring boot latest uses ooold version)

Another thing that worked is use a bogus placeholder prefix and that did the trick...

flyway.placeholderPrefix=$$$-bogus-$$$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM