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

Ensure Realm migration does not crash #8965

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.matrix.android.sdk.internal.crypto.store.db.migration

import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.extensions.safeRemove
import org.matrix.android.sdk.internal.util.database.RealmMigrator

internal class MigrateCryptoTo024(realm: DynamicRealm) : RealmMigrator(realm, 24) {
Expand All @@ -32,20 +33,20 @@ internal class MigrateCryptoTo024(realm: DynamicRealm) : RealmMigrator(realm, 24
get("CryptoRoomEntity")?.removeField("outboundSessionInfo")

// Warning: order is important, first remove classes that depends on others.
remove("UserEntity")
remove("DeviceInfoEntity")
remove("CrossSigningInfoEntity")
remove("KeyInfoEntity")
remove("TrustLevelEntity")
remove("KeysBackupDataEntity")
remove("OlmInboundGroupSessionEntity")
remove("OlmSessionEntity")
remove("AuditTrailEntity")
remove("OutgoingKeyRequestEntity")
remove("KeyRequestReplyEntity")
remove("WithHeldSessionEntity")
remove("SharedSessionEntity")
remove("OutboundGroupSessionInfoEntity")
safeRemove("UserEntity")
safeRemove("DeviceInfoEntity")
safeRemove("CrossSigningInfoEntity")
safeRemove("KeyInfoEntity")
safeRemove("TrustLevelEntity")
safeRemove("KeysBackupDataEntity")
safeRemove("OlmInboundGroupSessionEntity")
safeRemove("OlmSessionEntity")
safeRemove("AuditTrailEntity")
safeRemove("OutgoingKeyRequestEntity")
safeRemove("KeyRequestReplyEntity")
safeRemove("WithHeldSessionEntity")
safeRemove("SharedSessionEntity")
safeRemove("OutboundGroupSessionInfoEntity")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.extensions
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.RealmObjectSchema
import io.realm.RealmSchema
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
import org.matrix.android.sdk.internal.util.fatalError

Expand Down Expand Up @@ -52,3 +53,9 @@ internal fun RealmObjectSchema?.forceRefreshOfHomeServerCapabilities(): RealmObj
obj.setLong(HomeServerCapabilitiesEntityFields.LAST_UPDATED_TIMESTAMP, 0)
}
}

internal fun RealmSchema.safeRemove(className: String) {
if (get(className) != null) {
remove(className)
}
}
Loading