realm-js
realm-js copied to clipboard
Version mismatch does not block sync
How frequently does the bug occur?
Always
Description
In React Native with synced Realm offline first: When the Realm schema is updated with breaking changes, even with available migrations, all users who do not update their app before going online with an old local Realm lose all their data. Nothing (to my knowledge) can prevent the sync from happening, even though the app needs to be updated and the migrations applied first.
Example: My app is currently in version 1.1.9. The schema has been updated with breaking changes today. Those changes are handled by migrations in the app using "onMigration" function on the RealmProvider if a user updates to version 1.1.9. If a user was connected last week in version 1.1.8 and stayed offline until today, they will have 2 choices:
- Stay offline, close the app, update the app which applies the migrations, and open the app -> success OR
- Have the app opened, get an internet signal, Realm will automatically sync with the cloud, schema inconsistency: client reset -> data lost forever
I cannot ask all my clients to check for a new update whenever they find an internet signal. As far as I know, there is no way to prevent that at the moment, which is a complete blocking point for our product.
Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
- Create a Schema
- Connect with a synced Realm offline first
- Turn on airplane mode
- Update critical data locally offline
- Update the schema with breaking changes on Realm UI
- Create migrations to adapt local data to the new schema and publish them on the app store
- Do not update the app and turn on airplane mode: your critical data is lost forever
Version
12.6.2
What services are you using?
Both Atlas Device Sync and Atlas App Services
Are you using encryption?
Yes
Platform OS and version(s)
React Native iOS 17.4
Build environment
Which debugger for React Native: ..
Cocoapods version
No response
➤ PM Bot commented:
Jira ticket: RJS-2795
@kneth Is there a way to specify a version number to Realm and not allow Realm to sync if there is a version mismatch? A solution to not impact and destroy all data until the app is updated?
@HugoBounoua I am curious to know if you use RecoverUnsyncedChanges
as client reset mode?
v12.6.0 has a upgrade to Realm Core with https://github.com/realm/realm-core/pull/7239. Do you use flexible sync?
I'm curious about
Create migrations to adapt local data to the new schema and publish them on the app store
Unless RealmProvider does something I'm not aware of, onMigration
should only apply to local Realms and should never get executed for synchronized Realms.
Additionally, server-side schema migrations is not a feature that is enabled by default across all apps yet. Have you requested that it manually gets enabled for your app?
Have you requested that it manually gets enabled for your app?
I don't think that's possible yet. Also, this will be done automatically soon by the client if async open is used (so users need connectivity) and the new schema contains the following subset of breaking changes (remove table, remove property, change optional property to required, change required property to optional)