OrderHub Day 2 let Hibernate create the schema with ddl-auto: update — fine for a demo, scary for a real team (unversioned, unreviewable, and it quietly guesses changes). Day 3 does it properly: versioned migrations with Flyway.
🦋 See migrations apply in order: https://dev48v.infy.uk/orderhub/day3-flyway.html
Schema as version-controlled SQL
Instead of letting the ORM mutate the database, you write ordered SQL files:
db/migration/
V1__create_orders_table.sql
V2__add_order_indexes.sql
On startup Flyway checks a flyway_schema_history table, runs any migrations that haven't been applied yet — in version order — and records each. Every environment (your laptop, a teammate's, production) converges to the exact same schema, reproducibly.
The key switch
spring.jpa.hibernate.ddl-auto goes from update → validate. Flyway now owns the schema; Hibernate just checks that your @Entity still matches the migrated tables and fails fast if it drifts.
Rules that keep you safe
Migrations are append-only — never edit one that's already run; add a new V3__… instead. Keep the SQL portable (it runs on H2 locally and PostgreSQL in prod).
🔨 Full walkthrough (Flyway dep → V1/V2 files → ddl-auto: validate) on the page: https://dev48v.infy.uk/orderhub/day3-flyway.html
OrderHub — a production-grade Spring Boot backend, one feature a day.
🌐 https://dev48v.infy.uk · Code: https://github.com/dev48v/order-hub-from-zero
Top comments (0)