Why this matters
ddl-auto: updateis unpredictable in production — Flyway gives you repeatable, reviewable schema changes.- Migration files are the database equivalent of git commits: versioned, auditable, and reversible in principle.
- Zero-downtime deployments require careful migration ordering — Flyway's versioning model supports this.
Versioned SQL
L1 · FresherFiles like V1__create_books.sql apply in order; Flyway records history in flyway_schema_history.
Boot integration
L2 · IntermediateAdd flyway-core and migrations under db/migration — Boot runs them on startup before serving traffic.
Backward-compatible changes
L3 · AdvancedExpand-contract pattern: add nullable columns first, backfill, then enforce NOT NULL in a later release.
Repair and out-of-order
L4 · ExpertKnow flyway repair for failed migrations in lower environments; production changes always go through reviewed scripts.
Add Flyway
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
Flyway auto-configures when on the classpath. Set Hibernate to validate only:
spring:
jpa:
hibernate:
ddl-auto: validate
flyway:
enabled: true
locations: classpath:db/migration
Migration file naming
Files live in src/main/resources/db/migration/:
V1__create_books_table.sql
V2__create_authors_table.sql
V3__add_author_id_to_books.sql
V4__create_orders_table.sql
Convention: V{version}__{description}.sql. Double underscore separates version from description. Versions must be unique and sequential.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 7 sections
- V1: Initial schema
- V2: Add authors
- V3: Seed reference data
- Repeatable migrations
- Baseline for existing databases
- Zero-downtime patterns
- Flyway in CI
Test yourself
Answer these before moving on — recall is what makes it stick.