Testing: add Room migration tests (MigrationTestHelper), starting with 11 to 12 #63

Closed
opened 2026-07-01 21:17:30 +00:00 by JMR-dev · 0 comments
JMR-dev commented 2026-07-01 21:17:30 +00:00 (Migrated from github.com)

Origin: code review of PR #54, which added MIGRATION_11_12 — the first migration authored with both endpoint schemas exported (11.json + 12.json), and still no test runs it.

Problem

CLAUDE.md states: "Room schemas are exported to app/schemas and validated by migration tests — commit schema changes." That sentence is currently aspirational repo-wide:

  • No androidx.room:room-testing dependency exists; MigrationTestHelper appears only in comments (app/build.gradle.kts:140, LibreMailDatabaseTest.kt:25-27 "so future migrations can be tested").
  • LibreMailDatabaseTest builds fresh in-memory v12 databases — the migration DDL is never executed by any test.
  • DatabaseModule registers no destructive fallback (deliberately — dropping tables would lose stored secrets), so a drift between a migration and the entity/schema expectation crashes upgrading users with IllegalStateException("Migration didn't properly handle: folders") at first DB open, and nothing in CI would have caught it.

Suggested fix

  1. Add androidx.room:room-testing and a MigrationTest (androidTest) using MigrationTestHelper.
  2. Start with 11→12 (both schemas exported): create at v11, insert a folder row, runMigrationsAndValidate(12), assert specialUse defaults to 0 and data survives.
  3. Replay the whole exported chain (7→12) in one test so every future migration is covered automatically, and each new migration only needs the schema commit.

Migrations 1→2 … 10→11 predate exported schemas and are a pre-existing gap; the chain test covers everything from v7 on.

Origin: code review of PR #54, which added `MIGRATION_11_12` — the first migration authored with both endpoint schemas exported (11.json + 12.json), and still no test runs it. ## Problem CLAUDE.md states: "Room schemas are exported to `app/schemas` and validated by migration tests — commit schema changes." That sentence is currently aspirational repo-wide: - No `androidx.room:room-testing` dependency exists; `MigrationTestHelper` appears only in comments (`app/build.gradle.kts:140`, `LibreMailDatabaseTest.kt:25-27` "so **future** migrations can be tested"). - `LibreMailDatabaseTest` builds fresh in-memory v12 databases — the migration DDL is never executed by any test. - `DatabaseModule` registers no destructive fallback (deliberately — dropping tables would lose stored secrets), so a drift between a migration and the entity/schema expectation crashes upgrading users with `IllegalStateException("Migration didn't properly handle: folders")` at first DB open, and nothing in CI would have caught it. ## Suggested fix 1. Add `androidx.room:room-testing` and a `MigrationTest` (androidTest) using `MigrationTestHelper`. 2. Start with 11→12 (both schemas exported): create at v11, insert a folder row, `runMigrationsAndValidate(12)`, assert `specialUse` defaults to 0 and data survives. 3. Replay the whole exported chain (7→12) in one test so every future migration is covered automatically, and each new migration only needs the schema commit. Migrations 1→2 … 10→11 predate exported schemas and are a pre-existing gap; the chain test covers everything from v7 on.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: JMR-dev/LibreMail#63