Joe Masilotti
Joe Masilotti

Reputation: 17008

Best practices for infrequent updating to an Android database?

I have an Android application that installs a database (~2000 rows across all tables) to the device when it is first opened. The user can make minor changes to it (one column only) and it is only updated on a new version release.

Due to the nature of the database/application, it is not possible to put the data online (yet).

I am assuming I will install the database (onCreate) with a LOT of inserts, then update it every now and then, and then insert more rows (onUpdate?) with each new release. What would be the best practices for this procedure?

  1. Should I have an XML (or other structure) file that mimics the data and inserts every new row on every update from there?
  2. On each update should I erase all old data, or keep procedures inside of onUpdate() that depend on the current vs new database version (ex: version < X then update these rows and add these...)?
  3. The user can change a column (specific to that user) for each row. Would storing this in a preferences file make more sense?

Working with deployed databases is new to me, so any help would be appreciated!

Thanks!

Upvotes: 0

Views: 245

Answers (1)

Vladislav Rastrusny
Vladislav Rastrusny

Reputation: 29995

Well, I can suggest the migration way. Keep data version in the database. Make each application distribution have files like 1.0-to-1.3.upd, 1.3-to-1.4.upd holding all the update data to make a transition to a new version of the data.

Each OnUpdate() should check data version in the database and check a list of *.upd files it have to determine if data update is required. And then just applies necessary updates one by one, increasing data version in db each time.

This is like VBulletin and XenForo forums updates work.

Upvotes: 1

Related Questions