Java, Software Development, Spring Boot

Headstart Framework: Flyway and Supported Databases

We have designed the Headstart framework to be database-agnostic to support major database products with the help of Flyway. To achieve this database agnosticism, Headstart uses Spring Data/Hibernate but relies on migration scripts for creating database tables. We run these scripts using Flyway via Maven. Therefore, when there are changes to the database, we craft new migration scripts and apply the changes using Flyway.

Choose Headstart Framework Database Using Maven Profiles

The Headstart framework supports specific versions of MariaDB, MySQL, Microsoft SQL, Oracle, and PostgreSQL. To choose which database to use, we use a Maven profile corresponding to the RDBS we want our application to use. Consider the following snippet from the pom.xml  file.

Each Maven profile has a dependency on a supported database and a location to a Flyway configuration for the Headstart Framework to use. The Maven profile allows us to build and run our application with the database of our choice. Meanwhile, Flyway configuration allows Flyway to successfully run the appropriate migration scripts for the following Maven commands.

Application Properties for Headstart Framework

When we decide and configure which database to use, we start up the Headstart application using a set of .properties files for a specific environment and Spring profiles. These .properties files reside within a particular codebase directory but outside the resources directory, while the Spring profiles allow us to use additional .applications files.

Consider the following subdirectories under the src/main/config/env in the Headstart Framework codebase.

For the dev environment, we have application.properties, application-dev.properties, and .properties  file for a specific database. To run Headstart using PostgreSQL, we use the following VM options.

Then, Headstart uses the files  application.properties, application-dev.properties, and application-dbpg.properties in that order, and Spring Boot loads the values accordingly.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like