Atlassian Dan Lew Aug 16, 2016

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

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.

The article includes pseudocode for the exact test structure Trello uses to catch migration bugs before they reach production.

About This Article

Problem

Trello Android used to drop the entire database whenever the schema changed. This approach fell apart once the team started building offline functionality, because unsynced user data that hadn't reached the server yet could be lost.

Solution

Dan Lew's team built a file-based migration system. It stores one create.sql file plus numbered upgrade files like 1.sql, 2.sql, and so on. This lets you apply upgrades sequentially from any version to any other version.

Impact

They set up three layers of testing. Individual upgrade tests check each migration works. Schema equivalence validation ensures the end result is correct. Version bump enforcement prevents mistakes. Together, these eliminated the risk of unrecoverable database states and made it possible to develop migrations using test-driven development.