Add support for multiple flyway instances #38576
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
after my comment in another discussion to provide support for auto-configuring multiple beans I would like to contribute my solution for flyway. This is an integrated version from an internal adaption which we use in my company. The implementation is fully compatible with the current default behaviour.
To use the new behaviour you have to define properties like
spring.flyway.instances.{name}.*
. The {name} is a custom definition for the flyway instance. Every property tree overrides than the global properties which are placed inspring.flyway.*
. In general these are default-schema and location, but all other work too. Every instance can be disabled separately. Auto completion for properties works in the IDE too.In order to bind configuration beans to a flyway instance a new annotation
@FlywayInstance({name})
exists, which binds a bean to the specific instance by the {name} defined in the properties. When no explicit binding exists, the bean will be the default for all instances. ForFlywayConnectionDetails
,FlywayDataSource
andFlywayMigrationStrategy
a specific bean will be preferred. ForFlywayConfigurationCustomizer
undCallback
the default and the instance specific beans are joined by order. OnlyJavaMigration
expects an explicit binding, to avoid configuration errors. A predefinedFlywayMigrationInitializer
will only be used in the default mode. In multi instance mode every flyway bean gets its ownFlywayMigrationInitializer
.Most tests work and I added tests for the new feature. I can add documentation based on feedback.
Greetings,
Ben