Creating a Spring Boot Starter for Flyway Pro & Enterprise Editions

Florian Pfleiderer
Apr 30 · 4 min read

Over the past few years I have used Flyway as well as Spring Boot in several projects and have always enjoyed both of them for their simplicity and usability (disclaimer: I’m in no way affiliated with either boxfuse or Pivotal).

If you’re not familiar with it, Flyway is an open source tool that lets you manage your migrations for relational databases.
This means, that by using Flyway every schema change is done automatically and under the control of Flyway. No manual interaction is necessary.

With the recent release of version 5.0 the licensing model has been updated, introducing paid plans for new Pro and Enterprise editions. All editions provide binary compatibility to each other and can easily be exchanged, but unfortunately Spring Boot does not offer an out-of-the-box possibility to configure paid variants by adding a license key. As a means of help for anyone who wants to use Flyway Pro or Enterprise Edition with Spring boot 2.1 and higher, we at Digital Frontiers developed a small library that lets you do exactly that.

How does Flyway work?


By bundling together the application and database code, you can be sure that your database schema always matches what your code is expecting. The way most projects make use of this is by letting Flyway automatically perform migrations on application startup.
In order to do so, you just need to put your aptly named SQL files into a designated migrations folder so that they can be picked up by Flyway. During startup, they will be executed in a well-defined order. Flyway will remember which migrations have already been performed and will not do so again. That way you always know the exact state your database is in.

While Flyway’s well-known features still are and probably always will be available for free in its community edition, some additional features are only available in the Pro and Enterprise editions that have been introduced with the latest version. These features include, amongst others, Oracle SQL*Plus compatibility (Pro edition) or continued support for older versions of Java oder various databases (Enterprise edition). The full feature list can be found on the Flyway homepage.

And how to make it work with Spring Boot?


For a long time, Spring Boot did work like a charm with Flyway - and for the Community Edition it still does. But when migrating an app to the Enterprise edition for the first time, I had to learn that the application would not even start up due to Flyway lacking a license key.

Luckily, providing the key can be done as easily as calling Flyway’s FluentConfiguration.licenseKey() Method. Even more luckily, Spring Boot offers a really easy way to do that by adding the FlywayConfigurationCustomizer in its 2.1 release.

Combining those two, a license key can be set as easy as this:

FlywayConfigurationCustomizer for setting a license key

The FlywayConfigurationCustomizer will be picked up by Spring Boots FlywayAutoConfiguration and will be executed during startup to make sure the license key is set. A class like this is at the heart of our library. On top of that, it is sprinkled with all the nice convenient features you are used to from Spring Boot: AutoConfiguration, ConfigurationProperties, starter poms.

Thanks to the @ConfigurationProperties mechanism, you just have to set the spring.flyway.licenseKey property when you want to configure the license key. Though you could do this by hardcoding it in your application.yml, you should probably not do so because your license key will change over time. There is a variety of better mechanisms to provide it to the app, like environment variables or using Spring Vault.

The AutoConfiguration guarantees that a ConfigurationCustomizer is created whenever the license key property is set, so you don’t have to initialize it yourself. All you need to do is add the starter dependency to your project. Speaking of the starter, adding the dependency also takes care of importing the flyway dependency.

Combining all of those, the starter POMs are your ready-to-go package for using licensed Flyway editions with Spring Boot. If you want to use one, you can get it as a maven/gradle dependency (there is one for the Enterprise and one for the Pro Edition):

maven dependency for flyway enterprise
Property usage for setting flyway license key

As my colleague Frank explained in his previous blog post, we believe that contributing to open source is a vital part of getting the IT community ahead. So of course this lib is open source as well. It is released under the Apache 2.0 license, so feel free to use it and if you like it, contribute and help improving it further. If you have any suggestions or ideas, get in touch via the comments or Twitter and let us know what you think.

Digital Frontiers — Das Blog

Dies ist das Blog der Digital Frontiers GmbH & Co. KG ( Hier veröffentlichen wir zu Themen, die uns interessieren und bewegen.

Thanks to Frank Scheffler

Florian Pfleiderer

Written by

Senior Consultant & Co-Founder @dxfrontiers

Digital Frontiers — Das Blog

Dies ist das Blog der Digital Frontiers GmbH & Co. KG ( Hier veröffentlichen wir zu Themen, die uns interessieren und bewegen.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade