-
Work Log: Flyway Adoption for Sztab Database Migrations
Scope
Introduce Flyway as the standard mechanism for versioned PostgreSQL schema migrations across all Sztab environments: developer machines, CI, internal test deployments, and customer releases.
Estimated Time: 8–10 hours
Task Breakdown
1. Add Flyway Dependencies and Configuration (0.5h)
- Add Flyway starter to backend
pom.xml. - Configure
spring.flyway.*properties for dev/test/prod. - Verify Flyway auto-detection of migration folder.
2. Generate and Normalize Baseline Migration (2h)
- Extract current PostgreSQL schema using
pg_dump(schema-only). - Clean and reorder SQL for deterministic Flyway application.
- Save as
V1__baseline.sqlundersrc/main/resources/db/migration/. - Validate that the baseline matches existing live schemas.
3. Convert Existing Bootstrapping SQL (1h)
- Move any schema creation logic from
schema.sql, test scaffolding, or initializer code into structured Flyway migration files. - Remove redundant manual schema creation steps.
4. Disable Hibernate Auto-DDL (0.5h)
- Set
spring.jpa.hibernate.ddl-auto=noneacross all profiles. - Verify application boot without schema-generation warnings.
5. Update Integration Tests to Use Flyway (1h)
- Ensure Docker Compose PostgreSQL container is initialized via Flyway.
- Confirm migrations run before Spring Boot context loads in tests.
- Fix tests that implicitly relied on auto-DDL behavior.
6. Validate Full Workflow (2h)
- Local run: wipe DB, start app, verify migrations applied.
- CI run: migrations applied before backend tests.
- Deployment run: verify migrations executed in controlled order.
7. Write Team Migration Workflow Documentation (1h)
- How to create
VXXX__description.sqlmigrations. - Naming conventions and versioning rules.
- Branching model: how to handle parallel features requiring schema changes.
- Guidelines for SQL quality (idempotency, constraints, index naming, etc.).
Expected Outcomes
- Full elimination of schema drift during development.
- Deterministic, version-controlled DB evolution across environments.
- Cleaner CI runs with reproducible schema setup.
- Predictable customer upgrades with packaged migration sets.
- Removal of Hibernate auto-DDL reliance.
Notes
- Migration workflow must become a mandatory step for all schema-affecting changes.
- Future releases will include corresponding Flyway version ranges in release notes.
- Team should update integration test harness to ensure Flyway is always executed cleanly.
- Add Flyway starter to backend
| Type |
New Feature
|
| Priority |
Normal
|
| Assignee | |
| Version |
1.0
|
| Sprints |
n/a
|
| Customer |
n/a
|
Issue Votes (0)
Background
Sztab’s database schema is now evolving alongside the application. New features routinely introduce changes to tables, constraints, indexes, and seed data. Until now, schema changes have been handled informally during development, and the risk is growing:
As Sztab matures, we need a consistent, deterministic approach to database evolution for both day-to-day development and formal customer releases.
Problem Statement
Sztab currently lacks a unified mechanism to version, apply, and promote database schema changes. Hibernate auto-DDL is unsuitable for production and unreliable for repeatable evolution. Manual SQL execution is error-prone and does not scale across environments (dev => test => staging => prod). Without a migration system, schema drift becomes inevitable.
Proposal
Adopt Flyway as the standard tool for all Sztab database migrations.
Flyway provides:
This approach ensures every environment—developer laptops, automated tests, internal deployments, and external customers—runs the exact same sequence of schema updates.
Scope
This issue proposes adopting Flyway for two use cases:
1. Major Customer Releases
For releases shipped to clients or external environments:
V104__add_review_requirements.sql).This provides predictable upgrades and eliminates schema-related outages.
2. Incremental Development Releases
During active team development:
This keeps everyone on a consistent schema and significantly reduces debugging time.
Implementation Plan
src/main/resources/db/migration/folder in the backend project.Expected Outcomes