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

Database has an unsupported version (24) and cannot be upgraded. #8586

Open
huangzishan37 opened this issue May 12, 2024 · 10 comments
Open

Database has an unsupported version (24) and cannot be upgraded. #8586

huangzishan37 opened this issue May 12, 2024 · 10 comments
Assignees
Labels

Comments

@huangzishan37
Copy link

How frequently does the bug occur?

Always

Description

Hello, after upgrading my Realm database from version 4.4.1 to 10.49.2, I encountered crashes. The crash message indicates that the database has an unsupported version (9) and cannot be upgraded.

I followed the advice from this issue downgraded the Realm database to version 10.48.0. After downgrading, users who upgraded from version 4.4.1 to 10.48.0 were able to create Realm databases normally. However, those users who had already upgraded to version 10.49.2 and then downgraded to version 10.48.0 encountered crashes again, with the message "Database has an unsupported version (24) and cannot be upgraded."

Could you please advise on how to ensure that users on version 10.49.2 do not encounter crashes after downgrading?

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

10.49.2

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

iOS 17.4.1

Build environment

Xcode version: ...
Dependency manager and version: ...

Copy link

sync-by-unito bot commented May 12, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2358

@huangzishan37
Copy link
Author

In addition, it is best not to delete the original existing database and rebuild

@huangzishan37
Copy link
Author

I've looked through the documentation, and it seems that it's not possible to downgrade from 10.49.2 to 10.48.0 because Realm files written by 10.49.2 cannot be read by older versions of Realm. If we stick with 10.49.2, then those users who were previously on version 4.4.1 will continue to experience crashes. What should we do?

@nirinchev
Copy link
Member

To be clear, those errors are thrown as exceptions and don't cause crashes, which would be unrecoverable error that terminates the program indiscriminately.

One approach to handling that without deleting the database is hosting a server that uses a newer Realm Core version. When a user that was on 4.x tries to upgrade to the latest version of the app, you can handle the error message and display a prompt to the user telling them the app needs to do one-time upgrade of their database that requires an internet connection. Then you upload the database, open it on the server which upgrades the file format, then send it back to the device to open it with 10.49+. It's not ideal and may not work for all users if they have massive databases, but it's one way to mitigate the problem.

@huangzishan37
Copy link
Author

To be clear, those errors are thrown as exceptions and don't cause crashes, which would be unrecoverable error that terminates the program indiscriminately.

One approach to handling that without deleting the database is hosting a server that uses a newer Realm Core version. When a user that was on 4.x tries to upgrade to the latest version of the app, you can handle the error message and display a prompt to the user telling them the app needs to do one-time upgrade of their database that requires an internet connection. Then you upload the database, open it on the server which upgrades the file format, then send it back to the device to open it with 10.49+. It's not ideal and may not work for all users if they have massive databases, but it's one way to mitigate the problem.

Can you tell me what is the Realm Swift version number corresponding to version 9? I checked the release notes but couldn't find the Realm Swift version number corresponding to version 9.

@huangzishan37
Copy link
Author

It crashed here, "Realm must not be nil"
image

@huangzishan37
Copy link
Author

Can I determine this error through UnsupportedFileFormatVersion and Error Code == 16? If this error occurs, do I need to delete the database and recreate it?
image

@nirinchev
Copy link
Member

You can catch the error in a way similar to:

do {
	try Realm(configuration: config)
} catch let e as Realm.Error where e.code == .unsupportedFileFormatVersion {
    // Inform user and delete database
}

@mrtajo
Copy link

mrtajo commented May 14, 2024

Hello @nirinchev
I'm experiencing the same issue.
Thank you for your help :)

In your previous response, you suggested deleting the database when a version conflict occurs.
Does it get resolved by using RLMRealmConfiguration > migrationBlock > deleteData?
Or should I delete the database file itself?

The reason I ask this question is that the data stored using Realm is not important to the user.
It's okay to delete it.
So, it's fine to delete the data during the migration step.

@nirinchev
Copy link
Member

You need to delete the entire file - deleting the data inside the migration block will not work as we can't open a file that is so old.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants