Back to Lessons

Database Migrations Flyway

April 5, 2026

Schema Version Control

Track and manage database schema changes.

Flyway Setup

spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migration

V1__create_tables.sql:
CREATE TABLE products (id BIGINT PRIMARY KEY, name VARCHAR(100));

V2__add_indexes.sql:
CREATE INDEX idx_product_name ON products(name);

Migration Features

  • Automatic execution on startup
  • Version tracking table
  • Rollback support
  • Repeatable migrations