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

Auto migration is not working when adding a new property #1771

Closed
sembozdemir opened this issue Jun 2, 2024 · 3 comments
Closed

Auto migration is not working when adding a new property #1771

sembozdemir opened this issue Jun 2, 2024 · 3 comments
Labels
Encryption:Off Frequency:Always More-information-needed More information needed from the reporter. The issue will autoclose if no more information is given. O-Community Repro:Always SDK-Use:Local T-Bug Waiting-For-Reporter Waiting for more information from the reporter before we can proceed

Comments

@sembozdemir
Copy link

How frequently does the bug occur?

Always

Description

I am expecting that auto migration should work according to the documentation here when I add a new property. However, it is failing for some reason. I guess there is a bug or am I missing something? Could you please help with it?

const val realmSchemaVersion = 3L // it was 2L

private val config = RealmConfiguration
  .Builder(setOf(MessageRealmObject::class, PendingMessageRealmObject::class))
  .schemaVersion(realmSchemaVersion)
  .build()

@Keep
private class MessageRealmObject : RealmObject {
    @PrimaryKey
    var _id: String? = null
    var chatId: String? = null
    var role: String? = null
    var text: String? = null
    var createdAt: Long? = null
    var photoId: String? = null // new property
    var photoImageUrl: String? = null // new property
}

@Keep
private class PendingMessageRealmObject : RealmObject {
    @PrimaryKey
    var _id: RealmUUID = RealmUUID.random()
    var chatId: String? = null
    var text: String? = null
    var createdAt: Long? = null
}

private fun <T> withRealm(func: (realm: Realm) -> T): T {
    val realm: Realm = Realm.open(config)
    val returnValue = func(realm)
    realm.close()
    return returnValue
}

fun example() {
   // it crashes when withRealm is called.
   withRealm {}
}

Expected behavior
Auto migration should work

Actual behavior
App crashes with the following exception.

Stacktrace & log output

java.lang.IllegalStateException: [RLM_ERR_SCHEMA_MISMATCH]: Migration is required due to the following errors:
  - Property 'MessageRealmObject.photoId' has been added.
  - Property 'MessageRealmObject.photoImageUrl' has been added.

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

1.16.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 34

Build environment

Android Studio version: Android Studio Hedgehog | 2023.1.1 Patch
Gradle version: 8.2

Copy link

sync-by-unito bot commented Jun 2, 2024

➤ PM Bot commented:

Jira ticket: RKOTLIN-1098

@rorbech
Copy link
Contributor

rorbech commented Jul 1, 2024

Hi @sembozdemir. I have no issues updating and migrating from version 2->3 while adding the new properties. Are you sure that you updated the realmSchemaVersion and added photoId and photoImageUrl in the same go?

If you bump the version number and reboot the app without adding the properties, the schema will already have version 3. You will have to increment it again when adding the properties.

Otherwise please provide more details on how should be able to reproduce it in our end.

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed More-information-needed More information needed from the reporter. The issue will autoclose if no more information is given. labels Jul 1, 2024
Copy link
Contributor

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Encryption:Off Frequency:Always More-information-needed More information needed from the reporter. The issue will autoclose if no more information is given. O-Community Repro:Always SDK-Use:Local T-Bug Waiting-For-Reporter Waiting for more information from the reporter before we can proceed
Projects
None yet
Development

No branches or pull requests

2 participants