Android Schemas for Mobile Development
Article Summary
Dan Lew from Atlassian reveals how Trello Android went from dropping the entire database on every schema change to implementing proper upgrades. The reason? They were secretly building offline mode.
For years, Trello Android took a nuclear approach to database upgrades: drop everything and repopulate from the server. This worked fine when the server was the single source of truth. But when the team started building offline functionality, they needed a real migration strategy that wouldn't lose unsynced data.
Key Takeaways
- Store schema as assets: one create.sql plus numbered upgrade files (1.sql, 2.sql, etc.)
- Write individual tests for each upgrade path to prevent data loss
- Add a test that fails if DB_VERSION bumps without new upgrade tests
- Verify all sequential upgrades produce same schema as create.sql
- Sequential upgrades let you focus on one version transition at a time
Critical Insight
A simple file-based schema upgrade strategy with three types of automated tests gives you confidence that database migrations won't lose offline user data.