mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Merge pull request #6538 from vector-im/feature/bma/more_migration_log
More DB migration log
This commit is contained in:
commit
b0237a4e22
8 changed files with 79 additions and 44 deletions
1
changelog.d/6538.misc
Normal file
1
changelog.d/6538.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Log durations of DB migration and migration steps.
|
|
@ -17,16 +17,18 @@
|
|||
package org.matrix.android.sdk.internal.auth.db
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo001
|
||||
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo002
|
||||
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo003
|
||||
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo004
|
||||
import org.matrix.android.sdk.internal.auth.db.migration.MigrateAuthTo005
|
||||
import timber.log.Timber
|
||||
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class AuthRealmMigration @Inject constructor() : RealmMigration {
|
||||
internal class AuthRealmMigration @Inject constructor() : MatrixRealmMigration(
|
||||
dbName = "Auth",
|
||||
schemaVersion = 5L,
|
||||
) {
|
||||
/**
|
||||
* Forces all AuthRealmMigration instances to be equal.
|
||||
* Avoids Realm throwing when multiple instances of the migration are set.
|
||||
|
@ -34,11 +36,7 @@ internal class AuthRealmMigration @Inject constructor() : RealmMigration {
|
|||
override fun equals(other: Any?) = other is AuthRealmMigration
|
||||
override fun hashCode() = 4000
|
||||
|
||||
val schemaVersion = 5L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Auth Realm from $oldVersion to $newVersion")
|
||||
|
||||
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
|
||||
if (oldVersion < 1) MigrateAuthTo001(realm).perform()
|
||||
if (oldVersion < 2) MigrateAuthTo002(realm).perform()
|
||||
if (oldVersion < 3) MigrateAuthTo003(realm).perform()
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.matrix.android.sdk.internal.crypto.store.db
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo001Legacy
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo002Legacy
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo003RiotX
|
||||
|
@ -35,13 +34,22 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo
|
|||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo015
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo016
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo017
|
||||
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
||||
import org.matrix.android.sdk.internal.util.time.Clock
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Schema version history:
|
||||
* 0, 1, 2: legacy Riot-Android
|
||||
* 3: migrate to RiotX schema
|
||||
* 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6)
|
||||
*/
|
||||
internal class RealmCryptoStoreMigration @Inject constructor(
|
||||
private val clock: Clock,
|
||||
) : RealmMigration {
|
||||
) : MatrixRealmMigration(
|
||||
dbName = "Crypto",
|
||||
schemaVersion = 17L,
|
||||
) {
|
||||
/**
|
||||
* Forces all RealmCryptoStoreMigration instances to be equal.
|
||||
* Avoids Realm throwing when multiple instances of the migration are set.
|
||||
|
@ -49,14 +57,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(
|
|||
override fun equals(other: Any?) = other is RealmCryptoStoreMigration
|
||||
override fun hashCode() = 5000
|
||||
|
||||
// 0, 1, 2: legacy Riot-Android
|
||||
// 3: migrate to RiotX schema
|
||||
// 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6)
|
||||
val schemaVersion = 17L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Realm Crypto from $oldVersion to $newVersion")
|
||||
|
||||
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
|
||||
if (oldVersion < 1) MigrateCryptoTo001Legacy(realm).perform()
|
||||
if (oldVersion < 2) MigrateCryptoTo002Legacy(realm).perform()
|
||||
if (oldVersion < 3) MigrateCryptoTo003RiotX(realm).perform()
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.matrix.android.sdk.internal.database
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo001
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo002
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo003
|
||||
|
@ -51,12 +50,15 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030
|
|||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031
|
||||
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032
|
||||
import org.matrix.android.sdk.internal.util.Normalizer
|
||||
import timber.log.Timber
|
||||
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RealmSessionStoreMigration @Inject constructor(
|
||||
private val normalizer: Normalizer
|
||||
) : RealmMigration {
|
||||
) : MatrixRealmMigration(
|
||||
dbName = "Session",
|
||||
schemaVersion = 32L,
|
||||
) {
|
||||
/**
|
||||
* Forces all RealmSessionStoreMigration instances to be equal.
|
||||
* Avoids Realm throwing when multiple instances of the migration are set.
|
||||
|
@ -64,11 +66,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
|
|||
override fun equals(other: Any?) = other is RealmSessionStoreMigration
|
||||
override fun hashCode() = 1000
|
||||
|
||||
val schemaVersion = 32L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Realm Session from $oldVersion to $newVersion")
|
||||
|
||||
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
|
||||
if (oldVersion < 1) MigrateSessionTo001(realm).perform()
|
||||
if (oldVersion < 2) MigrateSessionTo002(realm).perform()
|
||||
if (oldVersion < 3) MigrateSessionTo003(realm).perform()
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
package org.matrix.android.sdk.internal.raw
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.raw.migration.MigrateGlobalTo001
|
||||
import timber.log.Timber
|
||||
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class GlobalRealmMigration @Inject constructor() : RealmMigration {
|
||||
internal class GlobalRealmMigration @Inject constructor() : MatrixRealmMigration(
|
||||
dbName = "Global",
|
||||
schemaVersion = 1L,
|
||||
) {
|
||||
/**
|
||||
* Forces all GlobalRealmMigration instances to be equal.
|
||||
* Avoids Realm throwing when multiple instances of the migration are set.
|
||||
|
@ -30,11 +32,7 @@ internal class GlobalRealmMigration @Inject constructor() : RealmMigration {
|
|||
override fun equals(other: Any?) = other is GlobalRealmMigration
|
||||
override fun hashCode() = 2000
|
||||
|
||||
val schemaVersion = 1L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Global Realm from $oldVersion to $newVersion")
|
||||
|
||||
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
|
||||
if (oldVersion < 1) MigrateGlobalTo001(realm).perform()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
package org.matrix.android.sdk.internal.session.identity.db
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.session.identity.db.migration.MigrateIdentityTo001
|
||||
import timber.log.Timber
|
||||
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class RealmIdentityStoreMigration @Inject constructor() : RealmMigration {
|
||||
internal class RealmIdentityStoreMigration @Inject constructor() : MatrixRealmMigration(
|
||||
dbName = "Identity",
|
||||
schemaVersion = 1L,
|
||||
) {
|
||||
/**
|
||||
* Forces all RealmIdentityStoreMigration instances to be equal.
|
||||
* Avoids Realm throwing when multiple instances of the migration are set.
|
||||
|
@ -30,11 +32,7 @@ internal class RealmIdentityStoreMigration @Inject constructor() : RealmMigratio
|
|||
override fun equals(other: Any?) = other is RealmIdentityStoreMigration
|
||||
override fun hashCode() = 3000
|
||||
|
||||
val schemaVersion = 1L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Realm Identity from $oldVersion to $newVersion")
|
||||
|
||||
override fun doMigrate(realm: DynamicRealm, oldVersion: Long) {
|
||||
if (oldVersion < 1) MigrateIdentityTo001(realm).perform()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2022 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.util.database
|
||||
|
||||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import timber.log.Timber
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
internal abstract class MatrixRealmMigration(
|
||||
private val dbName: String,
|
||||
val schemaVersion: Long,
|
||||
) : RealmMigration {
|
||||
final override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Realm $dbName from $oldVersion to $newVersion")
|
||||
val duration = measureTimeMillis {
|
||||
doMigrate(realm, oldVersion)
|
||||
}
|
||||
Timber.d("Migrating Realm $dbName from $oldVersion to $newVersion took $duration ms.")
|
||||
}
|
||||
|
||||
abstract fun doMigrate(realm: DynamicRealm, oldVersion: Long)
|
||||
}
|
|
@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.util.database
|
|||
import io.realm.DynamicRealm
|
||||
import io.realm.RealmObjectSchema
|
||||
import timber.log.Timber
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
internal abstract class RealmMigrator(
|
||||
private val realm: DynamicRealm,
|
||||
|
@ -26,7 +27,10 @@ internal abstract class RealmMigrator(
|
|||
) {
|
||||
fun perform() {
|
||||
Timber.d("Migrate ${realm.configuration.realmFileName} to $targetSchemaVersion")
|
||||
doMigrate(realm)
|
||||
val duration = measureTimeMillis {
|
||||
doMigrate(realm)
|
||||
}
|
||||
Timber.d("Migrate ${realm.configuration.realmFileName} to $targetSchemaVersion took $duration ms.")
|
||||
}
|
||||
|
||||
abstract fun doMigrate(realm: DynamicRealm)
|
||||
|
|
Loading…
Reference in a new issue