Skip to content

feat(db): integrate Flyway for database migrations (#130)#310

Merged
nanotaboada merged 7 commits intomasterfrom
feat/130-flyway-database-migrations
Apr 10, 2026
Merged

feat(db): integrate Flyway for database migrations (#130)#310
nanotaboada merged 7 commits intomasterfrom
feat/130-flyway-database-migrations

Conversation

@nanotaboada
Copy link
Copy Markdown
Owner

@nanotaboada nanotaboada commented Apr 10, 2026

Summary

  • Add flyway-core and flyway-database-postgresql to pom.xml (Spring Boot manages the version)
  • Configure Flyway in src/main/resources/application.properties: spring.flyway.enabled=true, baseline-on-migrate=true, baseline-version=3; switch ddl-auto from none to validate
  • Disable Flyway in test environment (spring.flyway.enabled=false); tests continue using SQLite in-memory with ddl.sql/dml.sql
  • Create src/main/resources/db/migration/ with three versioned scripts: V1__Create_players_table.sql (schema), V2__Seed_starting11.sql (11 Starting XI players), V3__Seed_substitutes.sql (15 substitute players)
  • Update CHANGELOG.md and README.md with migration workflow documentation

Test plan

  • ./mvnw clean install — 40/40 tests pass, all JaCoCo coverage checks met
  • docker compose build — image builds successfully
  • CodeRabbit review — 2 findings dismissed (PG JDBC driver deferred to Add PostgreSQL support with unified migration-based initialization #286; validate is correct per issue spec)
  • Verify flyway_schema_history table is created on a fresh database run
  • Verify existing storage/players-sqlite3.db starts without running migrations (baselined at V3)

Closes #130

🤖 Generated with Claude Code


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Automated DB schema versioning and migrations on startup with seeded player data (starting XI and substitutes).
  • Documentation

    • Added migration guide: conventions, where migrations live, how to add/inspect migrations, sequencing and local reset steps.
  • Chores

    • Migrations enabled in production; test profile keeps in-memory DB initialization. Startup/container behavior updated: improved logs, configurable local DB path, image no longer includes pre-seeded DB, local DB files ignored.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d3721c42-938d-471b-9ece-f0bc977a5d7a

📥 Commits

Reviewing files that changed from the base of the PR and between 90e4421 and d7c2b74.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • scripts/entrypoint.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/entrypoint.sh
  • CHANGELOG.md

Walkthrough

Adds Flyway-based database migrations: Flyway deps and config, three versioned SQL migrations (schema + two seed sets), test profile keeps Flyway disabled and uses existing SQL scripts, updates Hibernate to validate, updates docs/changelog, and adjusts container startup/storage handling.

Changes

Cohort / File(s) Summary
Dependencies
pom.xml
Added Flyway dependencies including spring-boot-starter-flyway and flyway-database-postgresql.
App config
src/main/resources/application.properties, src/test/resources/application.properties
Enabled Flyway (spring.flyway.enabled=true) and set locations to classpath:db/migration; changed spring.jpa.hibernate.ddl-auto from none to validate; disabled Flyway for tests.
Migrations
src/main/resources/db/migration/V1__Create_players_table.sql, src/main/resources/db/migration/V2__Seed_starting11.sql, src/main/resources/db/migration/V3__Seed_substitutes.sql
Added V1 to create players table (columns include id VARCHAR(36), squadNumber, names, dateOfBirth, position, abbrPosition, team, league, starting11 BOOLEAN) and V2/V3 bulk-insert seed data (starting11 = 1 for V2, 0 for V3).
Test DDL
src/test/resources/ddl.sql
Changed test players DDL starting11 type from INTEGER to BOOLEAN to match migrations.
Docs & Changelog
README.md, CHANGELOG.md
Documented Flyway workflow, migration location/naming, migration sequencing, reset workflow, and test behavior.
Container & Entrypoint
Dockerfile, scripts/entrypoint.sh, .gitignore
Removed pre-seeded DB copy from Dockerfile; added storage/*.db to .gitignore; entrypoint refactor adds log() helper, STORAGE_PATH handling, writability checks, and skips image-copy initialization in favor of Flyway-driven init.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant App as Application
participant Flyway as Flyway
participant DB as Database
App->>Flyway: on startup, scan classpath:db/migration
Flyway->>DB: ensure flyway_schema_history exists
Flyway->>DB: apply pending migrations V1 → V2 → V3
DB-->>Flyway: migration results
Flyway-->>App: migrations applied
App->>DB: Hibernate validates schema; continue normal data access

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Add Flyway dependencies to pom.xml [#130]
Configure Flyway in application properties and set Hibernate ddl-auto=validate [#130]
Create migration directory and versioned SQL migrations V1, V2, V3 [#130]
Disable Flyway for tests and update README with migration workflow [#130]
Ensure migration SQL is compatible with both SQLite and PostgreSQL [#130] Migrations use BOOLEAN for starting11 (test DDL changed to BOOLEAN); the linked guidance recommended using INTEGER for cross-dialect boolean compatibility, so compatibility with both dialects is unclear.

Out-of-scope changes

Code Change Explanation
Removed pre-seeded DB copy step in Dockerfile (Dockerfile) This alters container image build/start behavior (removes copy of storage/ into image); not required by Flyway integration objectives.
Entrypoint storage/init refactor and logging changes (scripts/entrypoint.sh) Introduces STORAGE_PATH, writability checks, and removal of the prior image-to-volume copy flow; these runtime behavior changes extend beyond adding Flyway migrations.

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows Conventional Commits format (feat: prefix), is descriptive and specific about Flyway integration, stays well under 80 characters (57 chars), includes the JIRA issue reference (#130), and accurately reflects the main objective of integrating Flyway for database migrations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/130-flyway-database-migrations
  • 🛠️ sync documentation: Commit on current branch
  • 🛠️ sync documentation: Create PR
  • 🛠️ enforce http error handling: Commit on current branch
  • 🛠️ enforce http error handling: Create PR
  • 🛠️ idiomatic review: Commit on current branch
  • 🛠️ idiomatic review: Create PR
  • 🛠️ verify api contract: Commit on current branch
  • 🛠️ verify api contract: Create PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dc49f14) to head (d7c2b74).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #310   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity        30        30           
===========================================
  Files              2         2           
  Lines             88        88           
  Branches           8         8           
===========================================
  Hits              88        88           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 280-282: The fenced code block containing the pattern
"V{version}__{description}.sql" lacks a language specifier and triggers
markdownlint MD040; update the README's fenced block that contains that pattern
to include a language identifier such as "text" or "plaintext" (e.g., change the
opening backticks to ```text) so the block is treated as plain text and the lint
rule is satisfied.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d616c4db-73ae-44d0-be81-a7644529cfb1

📥 Commits

Reviewing files that changed from the base of the PR and between dc49f14 and 0b1b815.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • README.md
  • pom.xml
  • src/main/resources/application.properties
  • src/main/resources/db/migration/V1__Create_players_table.sql
  • src/main/resources/db/migration/V2__Seed_starting11.sql
  • src/main/resources/db/migration/V3__Seed_substitutes.sql
  • src/test/resources/application.properties

Comment thread README.md Outdated
nanotaboada and others added 5 commits April 10, 2026 11:52
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…tion (#130)

Hibernate 7 (Spring Boot 4.0.0) strictly validates Boolean → BOOLEAN;
INTEGER no longer satisfies the check. Update V1 migration and test DDL
to declare starting11 as BOOLEAN (native in PostgreSQL; stored as 0/1
with BOOLEAN affinity in SQLite). Regenerate storage/players-sqlite3.db
from the migration scripts so the pre-seeded Docker image matches.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…#130)

Flyway now handles database initialization, so the seed copy logic is
no longer needed. Align with the Rust entrypoint style: use a log()
helper for formatted output, add Swagger UI endpoint to the startup
banner, keep health check endpoint.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
baseline-on-migrate=true with baseline-version=3 caused Flyway to mark
an empty database as already at V3 (due to its own schema_history table
creation), skipping all migrations and leaving no players table. Remove
the baseline settings so Flyway runs V1→V2→V3 normally on first start.

Remove the pre-seeded storage/players-sqlite3.db from version control
and the Dockerfile COPY ./hold/ layer — Flyway now creates the database
and seeds all 26 players automatically. Add storage/.gitkeep and ignore
storage/*.db. Update README accordingly.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Spring Boot 4.0 moved Flyway auto-configuration out of
spring-boot-autoconfigure into a dedicated starter module. Adding only
flyway-core to the classpath is no longer sufficient to trigger
FlywayAutoConfiguration or the spring.flyway.* properties — the starter
is required, following the same convention as spring-boot-starter-data-jpa,
spring-boot-starter-webmvc, etc.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Around line 45-56: Update the CHANGELOG entry to reflect the final shipped
Flyway configuration: remove the assertion that `baseline-on-migrate=true` and
instead document that Flyway is enabled via `spring.flyway.enabled=true` and
configured with explicit `spring.flyway.locations` only (no
baseline-on-migrate), while tests remain disabled from Flyway and continue using
the SQLite in-memory DDL/DML approach; reference the existing mentions of
`spring.flyway.enabled`, `spring.flyway.locations`, and `baseline-on-migrate` in
the changelog text and adjust the sentence that currently states
`baseline-on-migrate=true` to match the actual shipped config.

In `@scripts/entrypoint.sh`:
- Around line 14-21: After creating the parent directory with mkdir -p
"$(dirname "$STORAGE_PATH")", add a fast-fail permissions check: verify the
parent directory is writable and that the database file at STORAGE_PATH is
writable or can be created (use a touch attempt or test -w on the file), and if
either check fails call log with a clear error including STORAGE_PATH and exit
1; update the startup block that currently logs existence to perform these
writability checks (referencing STORAGE_PATH, mkdir -p "$(dirname
"$STORAGE_PATH")" and the log function) so the script fails early with an
actionable message instead of letting the app error later.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de2ebc3e-f890-466f-a6e4-192e79b6b3c9

📥 Commits

Reviewing files that changed from the base of the PR and between d34b063 and 90e4421.

⛔ Files ignored due to path filters (2)
  • storage/.gitkeep is excluded by !**/storage/**
  • storage/players-sqlite3.db is excluded by !**/*.db, !**/storage/**, !**/*.db
📒 Files selected for processing (7)
  • .gitignore
  • CHANGELOG.md
  • Dockerfile
  • README.md
  • pom.xml
  • scripts/entrypoint.sh
  • src/main/resources/application.properties
💤 Files with no reviewable changes (1)
  • Dockerfile
✅ Files skipped from review due to trivial changes (2)
  • .gitignore
  • README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/resources/application.properties
  • pom.xml

Comment thread CHANGELOG.md Outdated
Comment thread scripts/entrypoint.sh
…130)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@nanotaboada nanotaboada merged commit 4cce977 into master Apr 10, 2026
12 checks passed
@nanotaboada nanotaboada deleted the feat/130-flyway-database-migrations branch April 10, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Flyway for database migrations

1 participant