Hi Guys,
Thank you for looking at my post and let me explain my situation :).
Background
The app in question is called Check Your Change, currently published in the Google Play Store.
We have about 20000 active users and over 100k installs over about 3 years. It’s a coin based app so UK coin collectors can mark off what coins they find in their change. We update the app regularly but being only a 1 man band with limited coding knowledge (basic Corona / Lua but proficient Swift / Xcode) we store all the data locally on the device and just manually update a pre loaded database each time.
The Problem
The problem we have is during the update process, we are seeing an increasing number of users lose their data. It is a low number like under 2% of reported cases but it is big enough that it is causing us problems and we really want to fix it for our users
The Update Process
Not having much experience with database migrations and limited info on how to persist data during updates, I ended up with the following solution:
A master database contains all of our coin data.
It is stored in the resource directory.
When a user opens the app for the first time, the database is copied to the users documents directory.
Users manipulate data through the app and it writes to their database in the documents directory.
During an update, I have a column in the databases called version, If the versions don’t match then an update is performed…
The user database is read and any data that needs to be persisted is written to arrays.
The user database is deleted.
The master database (with a higher version than what the user database was) is copied to the users documents directory.
The data in the arrays is written to the newly copied database, which just involves looping through the arrays and updating the newly copied database.
My Theories
IS this totally the wrong way to update user data?
Am I doing something incredibly stupid in my code that means a database is being closed before the loops are finishing through the user data?
Is it a limitation of Corona?
Is it something database related?
Is it something Android system related? (there appears to be no pattern to the devices involved)
Is it something to do with not being able to multi thread?
I have had problems with the activityIndicator performing incorrectly during the update too. Originally I had it timer based but then changed it all to try and resolve the issue.
I have spent many sleepless nights and hours looking into this problem and I can never replicate it, we beta test each update with about 10 devices and we can never replicate it but there is a hidden daemon there and I thought I would try reaching out to see if anyone has any ideas or advice?
I have attached my code with comments for the update process if anyone would be kind enough to have a look.
Kind Regards,
Mike.
