Return to site

🍃🚀 FLYWAY with SPRING BOOT in 5 practical STEPSAdd a Blog Post Title

· spring

Ship database changes with Flyway + Spring Boot in 5 baby-steps.

🔸 WHAT IS FLYWAY?

Flyway is a database migration tool that versions schema changes alongside your application code.

It executes pending migrations in order and records their versions, checksums and results in flyway_schema_history.

🔸 TLDR

Add Flyway, configure the database, place versioned SQL files in db/migration, then start the application.

Spring Boot automatically runs the pending migrations during startup.

1️⃣ ADD THE DEPENDENCIES

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-flyway</artifactId>
</dependency>

<dependency>
 <groupId>org.flywaydb</groupId>
 <artifactId>flyway-database-postgresql</artifactId>
</dependency>

<dependency>
 <groupId>org.postgresql</groupId>
 <artifactId>postgresql</artifactId>
 <scope>runtime</scope>
</dependency>public class HelloWorld {
 public static void main(String[] args) {
  System.out.println("Hello World");
 }
}

The starter provides Spring Boot integration. PostgreSQL also requires its Flyway database module and JDBC driver.

2️⃣ CONFIGURE THE DATABASE

spring:
 datasource:
 url: jdbc:postgresql://localhost:5432/shop
 username: shop_app
 password: ${DB_PASSWORD}
 jpa:
 hibernate:
 ddl-auto: validate
 flyway:
 locations: classpath:db/migration

Use Flyway to change the schema and Hibernate to validate it. Avoid ddl-auto: update, which would let Hibernate modify the database outside your migration history.

3️⃣ CREATE THE FIRST MIGRATION

src/main/resources/db/migration/V1__create_customer.sql
CREATE TABLE customer (
 id BIGINT GENERATED BY DEFAULT AS IDENTITY
 PRIMARY KEY,
 email VARCHAR(255) NOT NULL UNIQUE,
 created_at TIMESTAMP NOT NULL
);

Flyway recognises the V1__description.sql convention. At startup, it executes this script once and records its checksum.

4️⃣ EVOLVE THE SCHEMA

V2__add_customer_status.sql
ALTER TABLE customer
 ADD COLUMN status VARCHAR(30)
 NOT NULL DEFAULT 'ACTIVE';
CREATE INDEX idx_customer_status
 ON customer(status);

Never rewrite an already-deployed V1. Create a new migration so every environment follows the same reproducible history.

5️⃣ START AND VERIFY

./mvnw spring-boot:run
SELECT version, description, success
FROM flyway_schema_history
ORDER BY installed_rank;

Spring Boot calls Flyway during startup. Flyway finds V1 and V2, applies only the pending migrations and then allows the application to continue.

🔸 WHAT CHANGED IN FLYWAY 13.0?

Flyway 13.0.0, released July 20, 2026, added:

▪️ A development-time MCP server for AI agents 🤖

▪️ IDs for individual drift differences 🎯

▪️ Oracle online-index configuration support 🏛️

▪️ Clearer Docker provisioner and SQL errors 🔎

▪️ A security-related Jackson upgrade 🔐

#Flyway #SpringBoot #Java #PostgreSQL #DatabaseMigrations #SQL #DevOps #BackendDevelopment

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaBook👇