-
Type: Improvement
-
Resolution: Incomplete
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: None
Problem
When migrating with AutomaticSchemaMigration, I get an IllegalArgumentException because I want to delete the Signature class, but it's no longer in the schema list because it doesn't make sense to keep it in the schema migration list.
I even tried with enumerates and it didn't work.
Here's an example:
Unable to find source-code formatter for language: kt. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
val MAILBOX_CONTENT_MIGRATION = AutomaticSchemaMigration { migrationContext -> val oldRealm = migrationContext.oldRealm val newRealm = migrationContext.newRealm if (oldRealm.schemaVersion() < 9 && newRealm.schemaVersion() >= 9) { migrationContext.newRealm.delete("Signature") } }
Exception
java.lang.IllegalArgumentException: Schema does not contain a class named 'Signature' 2023-10-16 19:48:36.541 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.schema.SchemaMetadata$DefaultImpls.getOrThrow(CachedClassKeyMap.kt:40) 2023-10-16 19:48:36.541 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.schema.CachedSchemaMetadata.getOrThrow(CachedClassKeyMap.kt:89) 2023-10-16 19:48:36.542 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.dynamic.DynamicMutableRealmImpl.query(DynamicMutableRealmImpl.kt:65) 2023-10-16 19:48:36.542 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.dynamic.DynamicRealm$DefaultImpls.query$default(DynamicRealm.kt:45) 2023-10-16 19:48:36.542 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.dynamic.DynamicMutableRealmImpl.delete(DynamicMutableRealmImpl.kt:106) 2023-10-16 19:48:36.542 24243-24443 System.err com.infomaniak.mail W at com.infomaniak.mail.data.cache.RealmMigrationsKt.MAILBOX_CONTENT_MIGRATION$lambda$2(RealmMigrations.kt:36) 2023-10-16 19:48:36.542 24243-24443 System.err com.infomaniak.mail W at com.infomaniak.mail.data.cache.RealmMigrationsKt.$r8$lambda$m8gC0trFnAvmBIhjEaMMi3q8yFo(Unknown Source:0) 2023-10-16 19:48:36.543 24243-24443 System.err com.infomaniak.mail W at com.infomaniak.mail.data.cache.RealmMigrationsKt$$ExternalSyntheticLambda2.migrate(Unknown Source:0) 2023-10-16 19:48:36.543 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.ConfigurationImpl.lambda$3$lambda$2(ConfigurationImpl.kt:171) 2023-10-16 19:48:36.543 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.ConfigurationImpl$$ExternalSyntheticLambda0.migrate(Unknown Source:4) 2023-10-16 19:48:36.543 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.interop.realmcJNI.realm_open(Native Method) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.interop.realmc.realm_open(realmc.java:426) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.interop.RealmInterop.realm_open(RealmInterop.kt:202) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.ConfigurationImpl$openRealm$2.invoke(ConfigurationImpl.kt:114) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.ConfigurationImpl$openRealm$2.invoke(ConfigurationImpl.kt:113) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.interop.NativePointerKt.use(NativePointer.kt:53) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.ConfigurationImpl.openRealm$suspendImpl(ConfigurationImpl.kt:113) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.ConfigurationImpl.openRealm(Unknown Source:0) 2023-10-16 19:48:36.544 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.RealmImpl$1.invokeSuspend(RealmImpl.kt:132) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1) 2023-10-16 19:48:36.545 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:22) 2023-10-16 19:48:36.546 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:21) 2023-10-16 19:48:36.546 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.RealmImpl.<init>(RealmImpl.kt:114) 2023-10-16 19:48:36.546 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.RealmImpl.<init>(Unknown Source:0) 2023-10-16 19:48:36.546 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.internal.RealmImpl$Companion.create$io_realm_kotlin_library(RealmImpl.kt:293) 2023-10-16 19:48:36.546 24243-24443 System.err com.infomaniak.mail W at io.realm.kotlin.Realm$Companion.open(Realm.kt:83) 2023-10-16 19:48:36.546 24243-24443 System.err com.infomaniak.mail W at com.infomaniak.mail.data.cache.RealmDatabase.newMailboxContentInstance(RealmDatabase.kt:80) 2023-10-16 19:48:36.547 24243-24443 System.err com.infomaniak.mail W at com.infomaniak.mail.data.cache.RealmDatabase.getNewMailboxContentInstance(RealmDatabase.kt:79) 2023-10-16 19:48:36.547 24243-24443 System.err com.infomaniak.mail W at com.infomaniak.mail.data.cache.RealmDatabase$MailboxContent$invoke$1.invokeSuspend(RealmDatabase.kt:85) 2023-10-16 19:48:36.547 24243-24443 System.err com.infomaniak.mail W at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
Version
Realm 1.11.1
Solution
I haven't found any other way than to leave the class in the schema migrations, but ideally it would be nice to be able to delete an existing class even if it no longer appears in the current schema migrations.
- Perhaps the oldRealm could contain a delete method, which would allow deletion based on the previous schema only (not a fan, as it would be confusing).
- Or a way to temporarily put the schema in the list until the migration is complete.
- Or just a way to delete without checking the schema during migration.
Alternatives
No response
How important is this improvement for you?
I would like to have it but have a workaround
Feature would mainly be used with
Local Database only