diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration43Test.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration43Test.kt index e74aa52495..af8d2fdd3b 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration43Test.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration43Test.kt @@ -56,7 +56,7 @@ class RealmSessionStoreMigration43Test { } @Test - fun migrationShouldBeNeeed() { + fun migrationShouldBeNeeded() { val realmName = "session_42.realm" val realmConfiguration = configurationFactory.createConfiguration( realmName, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt index 99734f654f..1b0143f4fa 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt @@ -39,6 +39,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo020 import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo021 import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo022 +import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo023 import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import org.matrix.android.sdk.internal.util.time.Clock import javax.inject.Inject @@ -54,7 +55,7 @@ internal class RealmCryptoStoreMigration @Inject constructor( private val rustMigrationInfoProvider: RustMigrationInfoProvider, ) : MatrixRealmMigration( dbName = "Crypto", - schemaVersion = 22L, + schemaVersion = 23L, ) { /** * Forces all RealmCryptoStoreMigration instances to be equal. @@ -91,5 +92,6 @@ internal class RealmCryptoStoreMigration @Inject constructor( rustMigrationInfoProvider.rustEncryptionConfiguration, rustMigrationInfoProvider.migrateMegolmGroupSessions ).perform() + if (oldVersion < 23) MigrateCryptoTo023(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/MigrateCryptoTo023.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/MigrateCryptoTo023.kt new file mode 100644 index 0000000000..1302b452bd --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/migration/MigrateCryptoTo023.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.crypto.store.db.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingKeyRequestEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +// Some fields are now required due to upgrade of Kotlin version. +// See https://github.com/realm/realm-java/issues/7810 for more details. +internal class MigrateCryptoTo023(realm: DynamicRealm) : RealmMigrator(realm, 23) { + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("OutgoingKeyRequestEntity") + ?.setRequired(OutgoingKeyRequestEntityFields.REQUEST_STATE_STR, true) + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 4a7064ebf5..e02ffc36c5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -71,6 +71,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo051 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo052 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo053 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo054 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo055 import org.matrix.android.sdk.internal.util.Normalizer import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import javax.inject.Inject @@ -79,7 +80,7 @@ internal class RealmSessionStoreMigration @Inject constructor( private val normalizer: Normalizer ) : MatrixRealmMigration( dbName = "Session", - schemaVersion = 54L, + schemaVersion = 55L, ) { /** * Forces all RealmSessionStoreMigration instances to be equal. @@ -143,5 +144,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 52) MigrateSessionTo052(realm).perform() if (oldVersion < 53) MigrateSessionTo053(realm).perform() if (oldVersion < 54) MigrateSessionTo054(realm).perform() + if (oldVersion < 55) MigrateSessionTo055(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt new file mode 100644 index 0000000000..3a0e79d3e7 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo055.kt @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.EventEntityFields +import org.matrix.android.sdk.internal.database.model.EventInsertEntityFields +import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntityFields +import org.matrix.android.sdk.internal.database.model.PushRulesEntityFields +import org.matrix.android.sdk.internal.database.model.PusherEntityFields +import org.matrix.android.sdk.internal.database.model.RoomEntityFields +import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.internal.database.model.presence.UserPresenceEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +// Some fields are now required due to upgrade of Kotlin version. +// See https://github.com/realm/realm-java/issues/7810 for more details. +internal class MigrateSessionTo055(realm: DynamicRealm) : RealmMigrator(realm, 55) { + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("EventEntity") + ?.setRequired(EventEntityFields.SEND_STATE_STR, true) + ?.setRequired(EventEntityFields.THREAD_NOTIFICATION_STATE_STR, true) + realm.schema.get("EventInsertEntity") + ?.setRequired(EventInsertEntityFields.INSERT_TYPE_STR, true) + realm.schema.get("LocalRoomSummaryEntity") + ?.setRequired(LocalRoomSummaryEntityFields.STATE_STR, true) + realm.schema.get("PushRulesEntity") + ?.setRequired(PushRulesEntityFields.KIND_STR, true) + realm.schema.get("PusherEntity") + ?.setRequired(PusherEntityFields.STATE_STR, true) + realm.schema.get("RoomEntity") + ?.setRequired(RoomEntityFields.MEMBERSHIP_STR, true) + ?.setRequired(RoomEntityFields.MEMBERS_LOAD_STATUS_STR, true) + realm.schema.get("RoomMemberSummaryEntity") + ?.setRequired(RoomMemberSummaryEntityFields.MEMBERSHIP_STR, true) + realm.schema.get("RoomSummaryEntity") + ?.setRequired(RoomSummaryEntityFields.MEMBERSHIP_STR, true) + ?.setRequired(RoomSummaryEntityFields.VERSIONING_STATE_STR, true) + realm.schema.get("UserPresenceEntity") + ?.setRequired(UserPresenceEntityFields.PRESENCE_STR, true) + } +}