Database migration bug, a nuclear bomb like problem.

This bug if not taken care of, will force your user to have no choice but uninstall your app. It’s like a nuclear bomb, eliminate your all your existing users.

It won’t be discovered when doing normal testing. And it could happen even with just a small change. A thorough migration testing is needed to ensure it doesn’t happen.

Let me share a simplified version of a real almost happen case…

The Version 1 App — simple single table Database

First you made a good App, it doesn’t have a database, with one table.

override fun onCreate(db: SQLiteDatabase) {
createTableA()
}
private fun createTableA() {
// Create table A
}

Simply good does what it has to. Many people install your app. You are happy :)

The Version 2 App—add another table

To make it better, now you add another Table. You also need to take care of migration.

override fun onCreate(db: SQLiteDatabase) {
createTableA()
createTableB()
}
override fun onUpgrade(db: SQLiteDatabase, oldV: Int, newV: Int) {
createTableB()
}
private fun createTableA()…

--

--