I have a very simple Spring Boot application which uses Flyway for database migrations. I want to set Flyway placeholders programmatically using Spring configuration class before migration starts.
What I do is:
@Configuration
public class FlywayConfiguration {
@Autowired
private Flyway flyway;
@Value("${threedsserver.db.tableSpaces.data:pg_default}")
private String tablespaceData;
@Value("${threedsserver.db.tableSpaces.index:pg_default}")
private String tablespaceIndex;
@Value("${threedsserver.db.tableSpaces.lob:pg_default}")
private String tablespaceLob;
@PostConstruct
void setFlywayPlaceholders() {
Map<String, String> placeholders = flyway.getPlaceholders();
placeholders.put("tablespace_data", tablespaceData);
placeholders.put("tablespace_index", tablespaceIndex);
placeholders.put("tablespace_lob", tablespaceLob);
flyway.setPlaceholders(placeholders);
}
}
Then in my migration script I use ${tablespace_data} property. The migration fails with :
No value provided for placeholder expressions: ${tablespace_data}
I suppose the migration starts before the configuration file is processed.
How to fix this? I don't want to use application.properties for setting flyway placeholders, but all other properties like spring.flyway.user, spring.flyway.password, etc want to be set by the application.properties.