1---2name: android-room-database3description: Model Room entities, DAOs, transactions, migrations, schema exports, and test-safe local persistence.4---5# Android Room Database67## When To Use8- Use this skill when the request is about: room database android, dao query migration android, room schema export.9- Primary outcome: Model Room entities, DAOs, transactions, migrations, schema exports, and test-safe local persistence.10- Reach for this skill when the hard part is schema design, DAO queries, transactions, migrations, or Room testing. Hand off to `android-rxjava-to-coroutines-migration` only if the main work is reactive API migration rather than the database contract itself.11- Handoff skills when the scope expands:12- `android-local-persistence-datastore`13- `android-testing-unit`1415## Workflow161. Start with the persistence contract: entities, keys, indexes, relations, and whether the data is source-of-truth, cache, or offline-first state.172. Model DAO access patterns explicitly, including transaction boundaries, query shape, paging, and invalidation behavior.183. Plan schema evolution before changing entities: exported schemas, migration steps, auto-migration eligibility, and destructive-fallback policy.194. Validate migration and query behavior with deterministic tests rather than assuming Room annotations are enough.205. Hand off DataStore, sync, or reactive API questions only after the Room boundary is correct.2122## Guardrails23- Export schemas and treat them as part of the contract, not optional tooling noise.24- Keep entities persistence-focused; map to domain/UI models instead of leaking table shape upward.25- Use explicit transactions for multi-step writes that must remain consistent.26- Test migrations against real old schemas before trusting them in release builds.2728## Anti-Patterns29- Treating Room entities as the app's domain model everywhere.30- Editing schemas without exporting or validating migration paths.31- Writing broad `SELECT *` queries when the screen only needs a narrow projection.32- Collapsing database, sync, and reactive-stream migration problems into one undifferentiated task.3334## Review Focus35- Entity keys, indexes, relations, and schema ownership.36- DAO query shape, transactions, and invalidation behavior.37- Migration safety, schema exports, and test coverage.38- Clear boundaries between Room models and higher-level app models.3940## Examples41### Happy path42- Scenario: Persist task items and reminder flags with schema-aware entities.43- Command: `cd examples/orbittasks-compose && ./gradlew :app:testDebugUnitTest`4445### Edge case46- Scenario: Recover from a failed schema change with an explicit migration path.47- Command: `python3 scripts/eval_triggers.py --skill android-room-database`4849### Failure recovery50- Scenario: Keep Room requests separate from DataStore, networking, and modernization prompts.51- Command: `cd examples/orbittasks-xml && ./gradlew :app:testDebugUnitTest`5253## Done Checklist54- Entities, DAOs, and transactions match the real persistence contract.55- Schema export and migration strategy are explicit.56- Query and migration tests cover the risky paths.57- Non-Room concerns are handed off instead of mixed into the database task.5859## Official References60- [https://developer.android.com/training/data-storage/room](https://developer.android.com/training/data-storage/room)61- [https://developer.android.com/training/data-storage/room/migrating-db-versions](https://developer.android.com/training/data-storage/room/migrating-db-versions)62- [https://developer.android.com/training/data-storage/room/accessing-data](https://developer.android.com/training/data-storage/room/accessing-data)63- [https://developer.android.com/training/data-storage/room/prepopulate](https://developer.android.com/training/data-storage/room/prepopulate)64- [https://developer.android.com/topic/performance/sqlite-performance-best-practices](https://developer.android.com/topic/performance/sqlite-performance-best-practices)