ioscore-datacore-data-migration

How to remedy data migration failure?


I wonder what to do if data migration fails when an iOS App is upgraded to a newer version? Since the App has actually been upgraded, does that mean the user lost his data for ever? Can the user, the App's developer, or the App do anything to get back the data saved in old schema?

I understand App developer should do everything possible to avoid this happen. But software is error-prone, I can't believe it never happened. How did people deal with it in those cases?

I ask this because I'm writing an App with a complex data modal. I expect I might make quite some changes to the data modal after its initial release. It would be good to know what I can do if such thing occurs.

I also think about providing a feature in the App to export data to a text file in App specific format, which uses a high level description language and works with different versions of the App. But the issue is iOS upgrade occurs automatically and user doesn't know when it occurs and export the data.


Solution

  • It's up to the developer to define sustainable data migration process. Approach should be taken depending on the kind of changes developer does.

    If some new attributes, entities or relations were added, or some properties of them were changed, it's enough to provide just the new model version. Developer should ensure that all the required relations are fulfilled after the migration.

    If you rename the relation, or delete relation, for example, one-to-one relation in order to make it one-to-many relation, this kind of change is probably error-prone. In this case, in the new app version developer should create another database which works on the new schema, and copy all data into it in the new format from the old schema.

    In this way even Xcode works when you upgrade it. For example, you can find databases of iOS device logs via ~/Library/Developer/Xcode/iOS Device Logs path, and every database name has Xcode app version in it. Xcode migrates previous database into the new one, without migration of the previous one in-situ.