Blog
Engineering
3
minutes

Perform Database Schema Migrations in Just 5 min Using Flyway and Spring Boot

At Qovery, we rely on Kotlin with Spring Boot to develop our API and Postgres as a database. When I joined the backend team a couple of months ago, we didn’t have a straightforward solution to handle database migrations. As production access is strictly limited, I had to depend on a teammate with admin rights every time I wanted to update the schema of the database. We needed to find a more appropriate long-term solution, as our team is fast-growing, and managing authorizations is bound to become even more painful. Eventually, we agreed to start using a database-migration tool and picked Flyway as the best tool for this job. The following article is about to show you how easily Flyway can integrate with an existing database using the Spring framework. It is not meant to provide a deep insight into Flyway, nor is it a step-by-step tutorial to set up the tool.
Mélanie Dallé
Senior Marketing Manager
Summary
Twitter icon
linkedin icon

What is Flyway?

Flyway is an open-source database migration tool that can handle more than a dozen SQL databases, including Postgres. It strongly favors simplicity and convention over configuration. Migrations can be written in either SQL or Kotlin, which is extremely useful when you need to migrate data with complex business logic. But most of all, Flyway offers plugins for many Java frameworks, such as Spring Boot—an obvious perk for us at Qovery, as it makes its integration super easy for us. Let me show you how it works!

Step 1 - Importing Flyway Into our Project

In our Gradle file, we need to add Flyway’s plugin and implementation as such:

// Add this Flyway plugin to the plugins section
plugins {
id "org.flywaydb.flyway" version "8.5.5"
}

// Add this Flyway plugin to the plugins section
dependencies {
implementation("org.flywaydb:flyway-core:8.4.3")
}

Step 2 - Updating our Spring Application Properties

For both application.properties files within the main and test folders, we need to add the following lines:

// Set to true if you are going to use Flyway with an existing database 
spring.flyway.baseline-on-migrate=true

// Version to use for the baseline, we used a timestamp of the date when we added Flyway
spring.flyway.baseline-version=1643814687

// Very important to disable the dangerous clean command on production environment
spring.flyway.clean-disabled=true

And that’s pretty much it! With this done, Flyway will create a flyway_schema_history table to store information about the state of your database.

If you are following Flyway’s conventions, you just need to add migration scripts to the src/main/resources/db/migration folder. They will then be executed when the application starts.

To learn more about Flyway’s conventions, feel free to check out their documentation on migrations.

[Bonus] Step 3 - Migration Generator

To make the process even smoother, we created a bash script to generate our migration files while respecting Flyway’s naming convention.

Every migration file’s name starts with V, followed by the version of the migration (in our case, we decided to use a timestamp to keep things simple). It is then followed by __ and the migration name.

Here’s how we create a migration:

> ./scripts/generate_migration AddInstallationIdToUser
> Created: .../src/main/resources/db/migration/V1648999476__add_installation_id_to_user.sql

Conclusion

Flyway has been great so far! All we had to do was set up the tool, go through its documentation to gain a proper understanding of how it works, and... that’s about it! No further tweaking involved! Thanks to this seamless implementation using Spring Boot, our development process has been significantly improved in a short amount of time and with very limited effort.

Share on :
Twitter icon
linkedin icon
Ready to rethink the way you do DevOps?
Qovery is a DevOps automation platform that enables organizations to deliver faster and focus on creating great products.
Book a demo

Suggested articles

SecurityAndCompliance
DevSecOps
 minutes
Qovery Achieves SOC 2 Type II Compliance

Qovery is officially SOC 2 Type II compliant with an Unqualified Opinion. Get the highest assurance of continuously verified security controls for enterprise-grade application deployments and simplify due diligence.

Pierre Mavro
CTO & Co-founder
Product
Observability
 minutes
Troubleshoot Faster with the New Log Search and Filtering in Qovery Observe

Following the launch of Qovery Observe, we’re progressively adding new capabilities to help you better monitor, debug, and understand your applications. Today, we’re excited to announce a major improvement to the Logs experience: you can now search and filter directly within your application logs.

Alessandro Carrano
Lead Product Manager
Platform Engineering
DevOps
Terraform
7
 minutes
Top 5 Crossplane Alternatives & Competitors

Go beyond Crossplane. Discover Qovery, the #1 DevOps automation tool, and 4 other IaC alternatives (Terraform, Pulumi) for simplified multi-cloud infrastructure management and deployment.

Morgan Perry
Co-founder
AWS
Platform Engineering
DevOps
9
 minutes
10 Best AWS ECS (Elastic Container Service) Alternatives

Compare the top 10 AWS ECS alternatives, including Qovery, Docker, EKS, and GKE. Find the best solution to simplify Kubernetes, automate DevOps, and achieve multi-cloud container deployment.

Morgan Perry
Co-founder
Platform Engineering
AWS
Kubernetes
DevOps
9
 minutes
10 Best EKS Alternatives: Simplifying Kubernetes for Modern Development

Compare the 10 best EKS alternatives for Kubernetes, including Qovery (IDP), GKE, DOKS, and OpenShift. Simplify operations, reduce costs, and accelerate deployment.

Morgan Perry
Co-founder
DevOps
Kubernetes
Platform Engineering
15
 minutes
Top 10 Openshift Alternatives & Competitors

Because various organizations need cloud application and service management that offers different levels of simplicity, cost-effectiveness, or feature sets than OpenShift, this article will review its top alternatives to help readers make an informed decision aligned with their specific infrastructure needs.

Morgan Perry
Co-founder
AI
Infrastructure Management
Product
5
 minutes
GPU workloads on EKS just got way simpler with Qovery

Running GPU workloads on EKS has never been easy, until now. With Qovery’s latest update, you can enable GPU nodes, configure GPU access, and optimize costs automatically, all without writing a single line of YAML or touching Helm charts. Qovery now handles everything behind the scenes so you can focus entirely on your applications.

Alessandro Carrano
Lead Product Manager
Kubernetes
 minutes
Kubernetes Deployment Strategies: Pros, Cons & Use Cases

Master Kubernetes deployment strategies: Rolling Update, Recreate, Blue/Green, and Canary. Learn the pros, cons, and use cases to choose the right strategy based on your uptime, risk tolerance, and resources. Simplify complex rollouts with automation.

Mélanie Dallé
Senior Marketing Manager

It’s time to rethink
the way you do DevOps

Say goodbye to DevOps overhead. Qovery makes infrastructure effortless, giving you full control without the trouble.