Flyway's configuration currently relies on JavaBean-style properties of the main Flyway class. For example:
Flyway flyway = new Flyway(); flyway.setDataSource("jdbc:myurl", "myuser", "secretpassword"); flyway.setLocations("classpath:db/mig"); flyway.migrate();
While having the advantage of being simple, it also comes at a cost: mutability. This makes it harder to perform certain kind of optimizations.
To remedy this Flyway 5.1 will introduce a new fluent configuration style which looks as follows:
Flyway.config() .dataSource("jdbc:myurl", "myuser", "secretpassword") .locations("classpath:db/mig").load() .migrate();
This has the advantage of being slightly more concise, while presenting Flyway with an immutable
This style should be the preferred style going forward for API usage.
For older technologies like Spring XML bean configuration, this however isn't a great fit. We are therefore also introducing
ClassicConfiguration configuration = new ClassicConfigution(); configuration.setDataSource("jdbc:myurl", "myuser", "secretpassword"); configuration.setLocations("classpath:db/mig"); Flyway flyway = new Flyway(configuration); flyway.migrate();
The original get and set methods from the
At that point we'll be able to fully take advantage of the immutability and the optimisation opportunities it offers.
The text was updated successfully, but these errors were encountered:
The snippet above doesn't compile, but this works:
Can you please confirm if this is the correct and recommended API usage for 5.1.1 and above?
P.S. also included this as a question on Stack Overflow: https://stackoverflow.com/questions/50845591/whats-the-officially-recommended-way-to-configure-flyway-5-1-x-programmatically
These Configuration changes are part of a larger overall story, in order to make Flyway instances immutable. Additional parts will be delivered in 5.2.
For now you have the choice, between the code as you presented it, and the existing setter-based approach.
In 5.2 we expect to add the static
We opted for this phased approach to gather feedback along the way. Even though this may not seem like much, it does impact every article and every piece of documentation ever written about the Flyway API, so we are threading very carefully here.
So if you do have feedback or remarks, now is the time. Please send them our way!
So I personally like the new way, as the whole configuration+migration procedure can be accomplished as a single statement and requires less code (skipping
Other improvements are great as well — e.g.
Thanks for the clarification!