Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local data gets lost on DataStore migration #1593

Open
valzevul opened this issue Jan 14, 2022 · 8 comments
Open

Local data gets lost on DataStore migration #1593

valzevul opened this issue Jan 14, 2022 · 8 comments
Labels
datastore Issues related to the DataStore category feature-request Request a new feature

Comments

@valzevul
Copy link

Describe the bug

Hey folks, every time models for Amplify are regenerated, let version in amplify/generated/models/AmplifyModels.swift changes (which is expected).

However, whenever I update the app, Amplify SDK compares the versions and if they are different migrates the database by removing the local copy and running a full sync against the remote copy.

This process doesn't trigger conflict resolution flows and docs mention that local migrations are not supported.

If that's the case, what are the best practices around the process? The app I am working on is offline-forward, so when users update there is a high chance they have lots of data not yet pushed to the servers, and losing it is less than ideal.

If that could be solved by selective sync (i.e as mentioned in #867), is there any timeline on its introduction to the iOS SDK?

Steps To Reproduce

Update an app with one version of AmplifyModels to another version of AmplifyModels, while having uncommited changes in the local database.

Expected behavior

The developer gets a chance to manually migrate / push uncommited changes.

Amplify Framework Version

1.18.1

Amplify Categories

DataStore

Dependency manager

Cocoapods

Swift version

5

CLI version

4.5.0

Xcode version

13.0

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Device

iPhone 13 Pro - Simulator

iOS Version

iOS 15

Specific to simulators

No response

Additional context

No response

@ameter ameter added datastore Issues related to the DataStore category pending-triage Issue is pending triage labels Jan 14, 2022
@dsaliberti
Copy link

Thanks @valzevul!
I'm also interested on that.
Looking forward for it

@diegocstn
Copy link
Contributor

hey @valzevul @dsaliberti,
we are aware of the limitations imposed by the lack of support for migrations of unsynced data and we're evaluating different options. We're not actively working on it but it's in our roadmap and something we want to address.

@valzevul
Copy link
Author

Hi @diegocstn, thanks for the heads up!

Good to know that this is on the roadmap, in the meantime I managed to temporarily address it on my side, although I don't yet know how reliable would that approach be:

  • On launch and before Amplify.configure() I check the let version in /generated/AmplifyModels.swift, and if it differs from the previous version I backup the db file used by DataStore
  • Once the remote migration is done I parse the backed up DB file, more specifically its MutationEvent table, and if there is anything there convert them back into Amplify models and insert / delete from the DataStore.

It seems to do the job but I guess there might be some edge cases I have missed (also relying on the private table might be less from ideal).

@diegocstn diegocstn added feature-request Request a new feature and removed pending-triage Issue is pending triage labels Feb 3, 2022
@lawmicha lawmicha added the p3 label Jun 8, 2022
@diegocstn diegocstn removed their assignment Jun 20, 2022
@dsaliberti
Copy link

Any good news on this one please? 😃

@altick
Copy link

altick commented Sep 5, 2023

One may wonder what real-world use cases is the Amplify Datastore designed for. To my knowledge, the offline-first solutions consider offline scenarios as their primary goal which means the local data should be treated as important and not just being thrown away.

@atierian atierian removed the p3 label Oct 16, 2023
@fzy-github
Copy link

@valzevul Would it be possible for you to share the parsing code of the internal amplify db table?

@valzevul
Copy link
Author

@fzy-spyro I've added a slightly simplified gist here, do let me know if there are any questions.

@amruth-movano
Copy link

@valzevul Hi, I am using iOS app and I faced the same issue now. Do you know the file path from where we can get the local amplify DB data. I saw your file, you used URL for dataStoreLocalCopyURL.absoluteString

But I downloaded the app container and I am unable to see any amplify file in it. Can you please help with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore category feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

9 participants