Android SQLite database migration simple tutorial

There are many tutorial out there that talks about SQLite Database for Android. But when it comes to migration, most tutorial just advice one to Drop and Recreate one, to simplify the tutorial.

However in real application, migration is essential as we would want to retain the user existing data even when they upgrade the App.

There are just close to none complete workable sample to guide new developer on migrating database. I suspect partly because it need to have two version to work it out, hence it’s quite cumbersome to do so.

With that I create one simple app on both version of DB (version 1 and 2) in different repo, which is workable and complete. You could just compile to test them out without need to change code to experiment the migration. The code is in Kotlin.

App with Database Version 1.

The project is at https://github.com/elye/demo_simpledb_ver1

In this project, is only a two simple classes i.e. MainActivity and DbHelper class. The MainActivity handles the UI operation of accepting user data, and clearing data, whereby the DbHelper handles all the Database needed operation.

There consist a very simple table with only ID (integer primary key) and NAME (non-nullable string)

--

--