Android SQLite schema migration with patches

3 05 2014

When upgrading your Android application you often need to change its data model. When the model is stored in SQLite database, then its schema must be updated as well. I recommend the concept of patching and versioning the database This is very well described in this article:

The idea behind it

Android lets you upgrade the schema version, detect its changes and react to it when user installs new app version with higher schema version. The SQLiteOpenHelper class that will notify you about this.

You need to override its onUpgrade() method. When onUpgrade() detects that current version is lower than new one, it can apply patches in order and migrate schema to the desired version.

I used that algorythm in one of my apps and it worked very well.



2 responses

3 05 2014
Robert Greathouse

Very cool! I’m glad you found it useful. Thanks for reading and recommending my article.

29 01 2016


Give Your feedback:

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: