realm / realm-js

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

Error: Database has an unsupported version (9) and cannot be upgraded, js engine: hermes, #6899

Closed Pingou closed 3 weeks ago

Pingou commented 1 month ago

How frequently does the bug occur?

Sometimes

Description

Some users are crashing with the Error: Database has an unsupported version (9) and cannot be upgraded, js engine: hermes message. Does that mean that if a user has an old version of my app because they disabled automatic updates, then they are s.o.l?

Stacktrace & log output

Fatal Exception: com.facebook.react.common.JavascriptException: Error: Database has an unsupported version (9) and cannot be upgraded, js engine: hermes, stack:
getSharedRealm@1:866814
Realm@1:1080086
anonymous@1:841222
loadModuleImplementation@1:80600
guardedLoadModule@1:80124
metroRequire@1:79754
anonymous@1:723470
loadModuleImplementation@1:80600
guardedLoadModule@1:80124
metroRequire@1:79754
anonymous@1:701659
loadModuleImplementation@1:80600
guardedLoadModule@1:80124
metroRequire@1:79754
anonymous@1:86644
loadModuleImplementation@1:80600
guardedLoadModule@1:80081
metroRequire@1:79754
global@1:79282

       at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:65)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
       at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:146)
       at com.facebook.jni.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
       at android.os.Looper.loop(Looper.java:246)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233)
       at java.lang.Thread.run(Thread.java:923)

Can you reproduce the bug?

No

Reproduction Steps

No response

Version

12.13.1

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android, rn 74.5

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

sync-by-unito[bot] commented 1 month ago

➤ PM Bot commented:

Jira ticket: RJS-2906

jayshah123 commented 1 month ago

I am also facing this issue on iOS only. I had upgraded sdk from 12.6.2 to 12.13.1, then downgraded from 12.13.1 to 12.11.1 but I still see this issue. I use realm just for local operations. What is the recommended upgrade path and fix here?

Pingou commented 3 weeks ago

@kraenhansen is there anyway to catch this error and do something with the database? The error comes from the C code right?

kraenhansen commented 3 weeks ago

This version of the database file format (9) is 4 years old (from Realm Core v5).

Beginning with RealmCore v14.0.0, you can only upgrade from version 10 and upwards. This means you'd have to pick a version of Realm JS using a Realm Core version lower than v14 to first upgrade the client and then upgrade Realm JS to a recent version in their app.

Sorry for the inconvenience this may cause, but it's an important goal of ours to keep the binary size of Realm Core low and removing migration logic to upgrade database files from ancient file format versions is one way to keep the size of the library low.

Pingou commented 3 weeks ago

@kraenhansen Thank you for the reply. I think you should have a very big warning on the github page, because it means that many users will lose all their data as there is no way to ensure that they will regularly update the app (unless you want to bypass Apple and Google and do some autoupdate thing, and even then it wouldn't work all the time). I appreciate all the work you've done but since I started using realm 7 years ago I wasted weeks on various issues (and I don't even need the complicated features), which is why I stay away from realm for all my new projects. Sorry to be negative for something provided for free, I really appreciate but I am very frustrated.

kraenhansen commented 3 weeks ago

many users will lose all their data as there is no way to ensure that they will regularly update

There is no requirement to regularly update. Although admittedly hard to pull off, you'd need to ensure the app gets upgraded in steps that are able to upgrade the file format along the way. You would need a way to control that very old versions upgrade to some "intermediate" version of your app first, before it takes the latest version. Some tools can achieve this through release channels, having a "legacy" and a latest channel, where you cannot upgrade from legacy to latest until you're on the latest version of "legacy". That being said, this is understandably frustrating to have to deal with as a developer - I agree this could have been better designed on our part.

I appreciate all the work you've done

Thanks 🙂 It's been a blast.

which is why I stay away from realm for all my new projects.

Since the project will EOL and not longer receive active maintenance, in less than a year from now, that's probably a wise choice 👍

Sorry to be negative for something provided for free, I really appreciate but I am very frustrated.

No worries: You're entirely entitled to your opinion and thanks for calling this out. We need feedback to improve (both positive and negative).

Pingou commented 3 weeks ago

@kraenhansen As far as I know there is no way to choose which binary to serve your users when they upgrade, it's all controlled by Apple and Google (I am talking about apps releasing on the app stores). They will always be served the last compatible versions (as in, compatible with their Android version). I do not use the sync or Atlas feature, it's unclear if I'm impacted by their deprecation.