# Add Flyway Database Migration Support ## Context The project has 4 Flyway-named migration files in `db/migration/` (V1-V4) but **Flyway is not in the dependencies**. Production uses `ddl-auto: validate` with no data seeding, so the V4 legal content was never inserted. Dev works because it uses `create-drop` + `db/h2/data.sql`. The goal: add Flyway so migrations run automatically on production PostgreSQL. ## Approach - **Production**: Flyway enabled, baseline at V3 (V1-V3 already applied manually), V4+ runs automatically - **Dev (H2)**: Flyway disabled — migration SQL uses PostgreSQL-specific syntax (`E'...\n...'`, `::jsonb`, `ON CONFLICT`) that H2 can't handle. Keep existing `create-drop` + `data.sql` ## Files to Modify ### 1. `pom.xml` — Add Flyway dependencies Add after the PostgreSQL dependency (line ~63): ```xml org.flywaydb flyway-core org.flywaydb flyway-database-postgresql ``` ### 2. `src/main/resources/application.yml` — Configure Flyway per profile **Dev profile** — disable Flyway (keep existing H2 setup): ```yaml spring: flyway: enabled: false ``` **Prod profile** — enable Flyway with baseline: ```yaml spring: flyway: enabled: true baseline-on-migrate: true baseline-version: 3 locations: classpath:db/migration ``` - `baseline-on-migrate: true` — on first run, creates `flyway_schema_history` table and marks V1-V3 as already applied - `baseline-version: 3` — everything up to V3 is assumed to already exist in the production DB - V4 (legal content) and any future migrations will execute automatically ## No Other Changes Needed - Migration files (V1-V4) are already correctly named and contain valid PostgreSQL SQL - Dev `data.sql` already seeds the same data using H2-compatible syntax - `ddl-auto: validate` stays in prod (Flyway manages schema, Hibernate validates) ## Verification 1. **Dev**: `mvn spring-boot:run` — H2 starts as before, `data.sql` seeds data, Flyway is off 2. **Prod**: Deploy with PostgreSQL — Flyway creates `flyway_schema_history`, baselines at V3, runs V4 to insert legal content 3. `curl https://mgmt.directlx.dev/api/v1/legal` — returns all 4 legal sections 4. Portal at `/portal/legal` — shows 4 documents in master-detail view