Skip to content

Commit 7500bba

Browse files
nanotaboadaclaude
andcommitted
fix(db): let Flyway own full DB lifecycle on fresh installs (#130)
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>
1 parent 0643be7 commit 7500bba

7 files changed

Lines changed: 10 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
HELP.md
22
.claude/settings.local.json
33
target/
4+
storage/*.db
45
!.mvn/wrapper/maven-wrapper.jar
56
!**/src/main/**/target/
67
!**/src/test/**/target/

Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ COPY --chmod=444 README.md ./
4444
COPY --chmod=555 scripts/entrypoint.sh ./entrypoint.sh
4545
COPY --chmod=555 scripts/healthcheck.sh ./healthcheck.sh
4646

47-
# The 'hold' is our storage compartment within the image. Here, we copy a
48-
# pre-seeded SQLite database file, which Compose will mount as a persistent
49-
# 'storage' volume when the container starts up.
50-
COPY --chmod=555 storage/ ./hold/
51-
5247
# Install SQLite runtime libs, add non-root user and prepare volume mount point
5348
RUN apk add --no-cache sqlite-libs && \
5449
addgroup -S spring && \

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ V{version}__{description}.sql
289289

290290
All migration SQL is written to be compatible with both **SQLite** (local dev) and **PostgreSQL** (see #286).
291291

292+
### First start
293+
294+
On first run, Flyway detects an empty database and applies V1 → V2 → V3 in sequence, creating the `players` table and seeding all 26 players. The database file (`storage/players-sqlite3.db`) is created automatically and is excluded from version control.
295+
292296
### Adding a new migration
293297

294298
Create a new file in `src/main/resources/db/migration/` with the next version number:
@@ -299,13 +303,9 @@ touch src/main/resources/db/migration/V4__Add_nationality_column.sql
299303

300304
Flyway applies it automatically on the next application startup. View the applied history by querying the `flyway_schema_history` table.
301305

302-
### Existing databases
303-
304-
`baseline-on-migrate=true` ensures that databases created before Flyway was introduced are recognised as already at `V3` (schema + full seed data), so no migrations run against them. Fresh databases (new file) run V1 → V2 → V3 from scratch.
305-
306306
### Reset local database
307307

308-
Delete the SQLite file and restart the application — Flyway recreates the schema and seed data automatically:
308+
Delete the SQLite file and restart — Flyway recreates the schema and seed data from scratch:
309309

310310
```bash
311311
rm storage/players-sqlite3.db

scripts/entrypoint.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fi
2222

2323
log "✔ Ready!"
2424
log "🚀 Launching app..."
25-
log "🔌 API endpoints | http://localhost:9000"
26-
log "📚 Swagger UI | http://localhost:9000/swagger/index.html"
27-
log "❤️ Health check | http://localhost:9001/actuator/health"
25+
log "🔌 API endpoints | http://localhost:9000"
26+
log "📚 Swagger UI | http://localhost:9000/swagger/index.html"
27+
log "❤️ Health check | http://localhost:9001/actuator/health"
2828
exec "$@"

src/main/resources/application.properties

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ spring.jpa.properties.hibernate.format_sql=true
2727

2828
# Flyway Database Migration Configuration
2929
# Flyway manages all schema creation and seed data via versioned SQL migrations.
30-
# baseline-on-migrate: treats an existing database (without flyway_schema_history)
31-
# as already at baseline-version, avoiding re-running migrations on pre-seeded DBs.
32-
# baseline-version=3: baselines existing databases at V3 (schema + all seed data
33-
# already applied), while fresh databases run V1 → V2 → V3 from scratch.
30+
# On first start, Flyway creates the database and runs V1 → V2 → V3 in order.
3431
spring.flyway.enabled=true
3532
spring.flyway.locations=classpath:db/migration
36-
spring.flyway.baseline-on-migrate=true
37-
spring.flyway.baseline-version=3

storage/.gitkeep

Whitespace-only changes.

storage/players-sqlite3.db

-16 KB
Binary file not shown.

0 commit comments

Comments
 (0)