Add Realm migrations due to upgrade of Kotlin version.

See https://github.com/realm/realm-java/issues/7810 for more details.
This commit is contained in:
Benoit Marty 2024-07-16 14:57:24 +02:00
parent 5203dd86b4
commit b3bd361a08
5 changed files with 94 additions and 3 deletions

View File

@ -56,7 +56,7 @@ class RealmSessionStoreMigration43Test {
} }
@Test @Test
fun migrationShouldBeNeeed() { fun migrationShouldBeNeeded() {
val realmName = "session_42.realm" val realmName = "session_42.realm"
val realmConfiguration = configurationFactory.createConfiguration( val realmConfiguration = configurationFactory.createConfiguration(
realmName, realmName,

View File

@ -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.MigrateCryptoTo020
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo021 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.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.database.MatrixRealmMigration
import org.matrix.android.sdk.internal.util.time.Clock import org.matrix.android.sdk.internal.util.time.Clock
import javax.inject.Inject import javax.inject.Inject
@ -54,7 +55,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(
private val rustMigrationInfoProvider: RustMigrationInfoProvider, private val rustMigrationInfoProvider: RustMigrationInfoProvider,
) : MatrixRealmMigration( ) : MatrixRealmMigration(
dbName = "Crypto", dbName = "Crypto",
schemaVersion = 22L, schemaVersion = 23L,
) { ) {
/** /**
* Forces all RealmCryptoStoreMigration instances to be equal. * Forces all RealmCryptoStoreMigration instances to be equal.
@ -91,5 +92,6 @@ internal class RealmCryptoStoreMigration @Inject constructor(
rustMigrationInfoProvider.rustEncryptionConfiguration, rustMigrationInfoProvider.rustEncryptionConfiguration,
rustMigrationInfoProvider.migrateMegolmGroupSessions rustMigrationInfoProvider.migrateMegolmGroupSessions
).perform() ).perform()
if (oldVersion < 23) MigrateCryptoTo023(realm).perform()
} }
} }

View File

@ -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)
}
}

View File

@ -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.MigrateSessionTo052
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo053 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.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.Normalizer
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
import javax.inject.Inject import javax.inject.Inject
@ -79,7 +80,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
private val normalizer: Normalizer private val normalizer: Normalizer
) : MatrixRealmMigration( ) : MatrixRealmMigration(
dbName = "Session", dbName = "Session",
schemaVersion = 54L, schemaVersion = 55L,
) { ) {
/** /**
* Forces all RealmSessionStoreMigration instances to be equal. * Forces all RealmSessionStoreMigration instances to be equal.
@ -143,5 +144,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
if (oldVersion < 52) MigrateSessionTo052(realm).perform() if (oldVersion < 52) MigrateSessionTo052(realm).perform()
if (oldVersion < 53) MigrateSessionTo053(realm).perform() if (oldVersion < 53) MigrateSessionTo053(realm).perform()
if (oldVersion < 54) MigrateSessionTo054(realm).perform() if (oldVersion < 54) MigrateSessionTo054(realm).perform()
if (oldVersion < 55) MigrateSessionTo055(realm).perform()
} }
} }

View File

@ -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)
}
}