Is it possible to combine lists of the same elements from multiple spring-boot configuration files written in YAML?
Example:
postgres.yml
contains my postgres db informations. It also contains the flyway location of my migration scripts:
---
flyway:
locations:
- flyway/migrations/postgres
The same with my oracle migrations:
---
flyway:
locations:
- flyway/migrations/oracle
Now if I want to start my application with test-data, I want to include my test_data
directory as well (those data work for both postgres and oracle):
---
flyway:
locations:
- flyway/test_data
When I run the application with active profiles postgres,testdata
the migrations are not loaded, since the locations entry is overridden by the test-data-file.
For this setup I could create four config-files to run each db with and without the test-data, but what would I do, if I have four different databases and three sets of test-data?
Unfortunately, as described in the Spring docs, this isn't currently possible. If you know the set of profile names ahead of time, you could probably work around this by creating separate lists, prefixed with the profile name, and then in your bean, have in it code that merges them into the final list. That code would just iterate over all known profile name prefixes, and if a profile was not active, that list would be empty.
Unfortunately, this seems harder if you don't own the bean, such as in your Flyway case. It might still be possible though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With