Odoo-mobile / framework

Odoo Mobile Framework
https://play.google.com/store/apps/dev?id=8607973775002477408
Other
330 stars 374 forks source link

DB is erased upon DATABASE_VERSION change #286

Closed warp10 closed 7 years ago

warp10 commented 7 years ago

According to the comment in Oconstants.java, DATABASE_VERSION should handle DB upgrade when it is incremented. Unfortunately, it looks like the whole db is erased upon apk reinstall instead.

Steps to reproduce: 1- install an apk with a certain DATABASE_VERSION and populate its db with a sync 2- bump DATABASE_VERSION up 3- reinstall the new apk 4- the db is completely erased

Expected behavior: 4- db schema is updated, and data is still loaded in tables

dpr-odoo commented 7 years ago

@warp10 Yes, the framework sample app will erase database when you upgrade database version, actually we have added that recreate database when db version upgrade. With latest commit (https://github.com/Odoo-mobile/framework/commit/127a8ba926152ea7dd7cd44a7a78d7c184bf8fcb) as referenced to this issue. You can now add your own upgrade script for model.

Each of model have to override onModelUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) method if you need to apply schema change script, other will be same as old schema.

warp10 commented 7 years ago

@dpr-odoo Thank you for your prompt patch. I'm sure that logic will be helpful in handling db transitions.

By the way, is there any recommendation/good practice you have regarding to code to be added to onModelUpgrade()? Or we just handle the upgrade as in any SQLite database?