Enable Room exportSchema and configure schemaLocation #9

Closed
opened 2026-06-28 09:09:05 +00:00 by admin · 0 comments
Owner

Context

Review of PR #8 flagged that AppDatabase is using exportSchema = false. This is fine for v1, but we need to flip it to true and configure room.schemaLocation before any future migration lands. Without exported schemas, Room's MigrationTestHelper can't auto-test migrations and we lose the safety net androidx.room:room-testing provides.

What to do

  1. Set exportSchema = true on @Database in app/src/main/java/dev/achmad/ledgerr/data/local/AppDatabase.kt.
  2. Add the Room schema location arg to app/build.gradle.kts:
    ksp {
        arg("room.schemaLocation", "$projectDir/schemas")
    }
    
  3. Commit the generated app/schemas/ directory (Room writes it on every annotation-processed build).
  4. Add app/schemas/ to git tracking (don't .gitignore it).

Why it matters

  • Prevents future PRs (e.g. #2 landing a v2 migration) from shipping a migration that wasn't tested.
  • Required by room-testing to do MigrationTestHelper round-trips.

When to do it

  • Before any issue that bumps the @Database(version = N).
  • This issue is essentially a precondition for #2 if a schema change is needed there; otherwise it can ship standalone.

Out of scope

  • Writing migrations (none exist yet — v1 is the only version).
  • Adopting room-testing.
## Context Review of PR #8 flagged that `AppDatabase` is using `exportSchema = false`. This is fine for v1, but we need to flip it to `true` and configure `room.schemaLocation` **before** any future migration lands. Without exported schemas, Room's `MigrationTestHelper` can't auto-test migrations and we lose the safety net `androidx.room:room-testing` provides. ## What to do 1. Set `exportSchema = true` on `@Database` in `app/src/main/java/dev/achmad/ledgerr/data/local/AppDatabase.kt`. 2. Add the Room schema location arg to `app/build.gradle.kts`: ```kotlin ksp { arg("room.schemaLocation", "$projectDir/schemas") } ``` 3. Commit the generated `app/schemas/` directory (Room writes it on every annotation-processed build). 4. Add `app/schemas/` to git tracking (don't `.gitignore` it). ## Why it matters - Prevents future PRs (e.g. #2 landing a v2 migration) from shipping a migration that wasn't tested. - Required by `room-testing` to do `MigrationTestHelper` round-trips. ## When to do it - **Before** any issue that bumps the `@Database(version = N)`. - This issue is essentially a precondition for #2 if a schema change is needed there; otherwise it can ship standalone. ## Out of scope - Writing migrations (none exist yet — v1 is the only version). - Adopting `room-testing`.
admin closed this issue 2026-06-28 12:55:35 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/ledgerr#9