realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.6k stars 558 forks source link

Version mismatch does not block sync #6603

Open HugoBounoua opened 2 weeks ago

HugoBounoua commented 2 weeks ago

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:

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

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

sync-by-unito[bot] commented 2 weeks ago

➤ PM Bot commented:

Jira ticket: RJS-2795

HugoBounoua commented 2 weeks ago

@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?

kneth commented 2 weeks ago

@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?

nirinchev commented 2 weeks ago

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?

danieltabacaru commented 2 weeks ago

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)