-
Notifications
You must be signed in to change notification settings - Fork 188
Discussion Restoring Old Databases
#Current Situation
We allow users to backup databases. We store them on the sdcard, we have them when they upgrade. We do not provide a way to restore them.
It is not uncommon for users to have an old export.csv but a newer database backup file.
In such circumstances, the user needs to send the developers the file to have an export created manually.
#Theory
A way to import an old database and merge it with the current database would be:
- run an export on the current DB
- copy the old database over the current one (ie. replace it)
- open the app and wait for it to upgrade the DB
- run an import of the csv file created at the start
#Practice
We could do this by:
- add a 'Import Old Database' dialog that allowed the user to select the file
- save a setting that indicated the DB was to restored on startup
- 'force close' the app (we are not supposed to do this)
- next time the user starts the app, StartupActivity will see the new setting and perform the following:
- run an export to a 'special' location (and disconnect!)
- backup current database to sdcard
- copy old database over current database
- connect to db to force an upgrade
- run an import on the 'special' export
The export/import can be ignored if the user just wants to restore an old DB.
Sadly, we are not supposed to 'force close' our own app. Which takes the lustre off this solution a little. We can do it via:
android.os.Process.killProcess(android.os.Process.myPid());
(after emitting a message to the user to restart the app).
#Alternative
We could modify CatalogueDbAdapter to accept a DB file name, and override getWritableDatabase() in DbHelper to allow acccess to old DB files. Then we would need to:
- copy the old DB file
- open it (and upgrade -- which is why we made a copy)
- copy authors/series/books/etc from the old DB to the new DB
This has the advantage of being kosher, and probably faster, and no force close required.
But it is probably a lot more work.