Realm migrations are not objects anymore
SchemaVersion is now a val
This commit is contained in:
parent
8a4ecf616a
commit
eed4bf175f
@ -46,7 +46,9 @@ internal abstract class AuthModule {
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@AuthDatabase
|
||||
fun providesRealmConfiguration(context: Context, realmKeysUtils: RealmKeysUtils): RealmConfiguration {
|
||||
fun providesRealmConfiguration(context: Context,
|
||||
realmKeysUtils: RealmKeysUtils,
|
||||
authRealmMigration: AuthRealmMigration): RealmConfiguration {
|
||||
val old = File(context.filesDir, "matrix-sdk-auth")
|
||||
if (old.exists()) {
|
||||
old.renameTo(File(context.filesDir, "matrix-sdk-auth.realm"))
|
||||
@ -58,8 +60,8 @@ internal abstract class AuthModule {
|
||||
}
|
||||
.name("matrix-sdk-auth.realm")
|
||||
.modules(AuthRealmModule())
|
||||
.schemaVersion(AuthRealmMigration.SCHEMA_VERSION)
|
||||
.migration(AuthRealmMigration)
|
||||
.schemaVersion(authRealmMigration.schemaVersion)
|
||||
.migration(authRealmMigration)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,17 @@ 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 timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal object AuthRealmMigration : RealmMigration {
|
||||
internal class AuthRealmMigration @Inject constructor() : RealmMigration {
|
||||
/**
|
||||
* Forces all AuthRealmMigration instances to be equal
|
||||
* Avoids Realm throwing when multiple instances of the migration are set
|
||||
*/
|
||||
override fun equals(other: Any?) = other is AuthRealmMigration
|
||||
override fun hashCode() = 4000
|
||||
|
||||
// Current schema version
|
||||
const val SCHEMA_VERSION = 4L
|
||||
val schemaVersion = 4L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Auth Realm from $oldVersion to $newVersion")
|
||||
|
@ -112,7 +112,8 @@ internal abstract class CryptoModule {
|
||||
@SessionScope
|
||||
fun providesRealmConfiguration(@SessionFilesDirectory directory: File,
|
||||
@UserMd5 userMd5: String,
|
||||
realmKeysUtils: RealmKeysUtils): RealmConfiguration {
|
||||
realmKeysUtils: RealmKeysUtils,
|
||||
realmCryptoStoreMigration: RealmCryptoStoreMigration): RealmConfiguration {
|
||||
return RealmConfiguration.Builder()
|
||||
.directory(directory)
|
||||
.apply {
|
||||
@ -121,8 +122,8 @@ internal abstract class CryptoModule {
|
||||
.name("crypto_store.realm")
|
||||
.modules(RealmCryptoStoreModule())
|
||||
.allowWritesOnUiThread(true)
|
||||
.schemaVersion(RealmCryptoStoreMigration.CRYPTO_STORE_SCHEMA_VERSION)
|
||||
.migration(RealmCryptoStoreMigration)
|
||||
.schemaVersion(realmCryptoStoreMigration.schemaVersion)
|
||||
.migration(realmCryptoStoreMigration)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
@ -33,16 +33,23 @@ import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo013
|
||||
import org.matrix.android.sdk.internal.crypto.store.db.migration.MigrateCryptoTo014
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal object RealmCryptoStoreMigration : RealmMigration {
|
||||
internal class RealmCryptoStoreMigration @Inject constructor() : RealmMigration {
|
||||
/**
|
||||
* Forces all RealmCryptoStoreMigration instances to be equal
|
||||
* Avoids Realm throwing when multiple instances of the migration are set
|
||||
*/
|
||||
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)
|
||||
const val CRYPTO_STORE_SCHEMA_VERSION = 14L
|
||||
val schemaVersion = 14L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.v("Migrating Realm Crypto from $oldVersion to $newVersion")
|
||||
Timber.d("Migrating Realm Crypto from $oldVersion to $newVersion")
|
||||
|
||||
if (oldVersion < 1) MigrateCryptoTo001Legacy(realm).perform()
|
||||
if (oldVersion < 2) MigrateCryptoTo002Legacy(realm).perform()
|
||||
|
@ -49,11 +49,6 @@ import javax.inject.Inject
|
||||
internal class RealmSessionStoreMigration @Inject constructor(
|
||||
private val normalizer: Normalizer
|
||||
) : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SESSION_STORE_SCHEMA_VERSION = 24L
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces all RealmSessionStoreMigration instances to be equal
|
||||
* Avoids Realm throwing when multiple instances of the migration are set
|
||||
@ -61,8 +56,10 @@ internal class RealmSessionStoreMigration @Inject constructor(
|
||||
override fun equals(other: Any?) = other is RealmSessionStoreMigration
|
||||
override fun hashCode() = 1000
|
||||
|
||||
val schemaVersion = 24L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.v("Migrating Realm Session from $oldVersion to $newVersion")
|
||||
Timber.d("Migrating Realm Session from $oldVersion to $newVersion")
|
||||
|
||||
if (oldVersion < 1) MigrateSessionTo001(realm).perform()
|
||||
if (oldVersion < 2) MigrateSessionTo002(realm).perform()
|
||||
|
@ -71,7 +71,7 @@ internal class SessionRealmConfigurationFactory @Inject constructor(
|
||||
}
|
||||
.allowWritesOnUiThread(true)
|
||||
.modules(SessionRealmModule())
|
||||
.schemaVersion(RealmSessionStoreMigration.SESSION_STORE_SCHEMA_VERSION)
|
||||
.schemaVersion(realmSessionStoreMigration.schemaVersion)
|
||||
.migration(realmSessionStoreMigration)
|
||||
.build()
|
||||
|
||||
|
@ -42,7 +42,8 @@ import org.matrix.android.sdk.internal.legacy.riot.HomeServerConnectionConfig as
|
||||
internal class DefaultLegacySessionImporter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val sessionParamsStore: SessionParamsStore,
|
||||
private val realmKeysUtils: RealmKeysUtils
|
||||
private val realmKeysUtils: RealmKeysUtils,
|
||||
private val realmCryptoStoreMigration: RealmCryptoStoreMigration
|
||||
) : LegacySessionImporter {
|
||||
|
||||
private val loginStorage = LoginStorage(context)
|
||||
@ -170,8 +171,8 @@ internal class DefaultLegacySessionImporter @Inject constructor(
|
||||
.directory(File(context.filesDir, userMd5))
|
||||
.name("crypto_store.realm")
|
||||
.modules(RealmCryptoStoreModule())
|
||||
.schemaVersion(RealmCryptoStoreMigration.CRYPTO_STORE_SCHEMA_VERSION)
|
||||
.migration(RealmCryptoStoreMigration)
|
||||
.schemaVersion(realmCryptoStoreMigration.schemaVersion)
|
||||
.migration(realmCryptoStoreMigration)
|
||||
.build()
|
||||
|
||||
Timber.d("Migration: copy DB to encrypted DB")
|
||||
|
@ -20,11 +20,17 @@ import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.raw.migration.MigrateGlobalTo001
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal object GlobalRealmMigration : RealmMigration {
|
||||
internal class GlobalRealmMigration @Inject constructor() : RealmMigration {
|
||||
/**
|
||||
* Forces all GlobalRealmMigration instances to be equal
|
||||
* Avoids Realm throwing when multiple instances of the migration are set
|
||||
*/
|
||||
override fun equals(other: Any?) = other is GlobalRealmMigration
|
||||
override fun hashCode() = 2000
|
||||
|
||||
// Current schema version
|
||||
const val SCHEMA_VERSION = 1L
|
||||
val schemaVersion = 1L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.d("Migrating Global Realm from $oldVersion to $newVersion")
|
||||
|
@ -51,14 +51,15 @@ internal abstract class RawModule {
|
||||
@Provides
|
||||
@GlobalDatabase
|
||||
@MatrixScope
|
||||
fun providesRealmConfiguration(realmKeysUtils: RealmKeysUtils): RealmConfiguration {
|
||||
fun providesRealmConfiguration(realmKeysUtils: RealmKeysUtils,
|
||||
globalRealmMigration: GlobalRealmMigration): RealmConfiguration {
|
||||
return RealmConfiguration.Builder()
|
||||
.apply {
|
||||
realmKeysUtils.configureEncryption(this, DB_ALIAS)
|
||||
}
|
||||
.name("matrix-sdk-global.realm")
|
||||
.schemaVersion(GlobalRealmMigration.SCHEMA_VERSION)
|
||||
.migration(GlobalRealmMigration)
|
||||
.schemaVersion(globalRealmMigration.schemaVersion)
|
||||
.migration(globalRealmMigration)
|
||||
.allowWritesOnUiThread(true)
|
||||
.modules(GlobalRealmModule())
|
||||
.build()
|
||||
|
@ -60,6 +60,7 @@ internal abstract class IdentityModule {
|
||||
@IdentityDatabase
|
||||
@SessionScope
|
||||
fun providesIdentityRealmConfiguration(realmKeysUtils: RealmKeysUtils,
|
||||
realmIdentityStoreMigration: RealmIdentityStoreMigration,
|
||||
@SessionFilesDirectory directory: File,
|
||||
@UserMd5 userMd5: String): RealmConfiguration {
|
||||
return RealmConfiguration.Builder()
|
||||
@ -68,8 +69,8 @@ internal abstract class IdentityModule {
|
||||
.apply {
|
||||
realmKeysUtils.configureEncryption(this, SessionModule.getKeyAlias(userMd5))
|
||||
}
|
||||
.schemaVersion(RealmIdentityStoreMigration.IDENTITY_STORE_SCHEMA_VERSION)
|
||||
.migration(RealmIdentityStoreMigration)
|
||||
.schemaVersion(realmIdentityStoreMigration.schemaVersion)
|
||||
.migration(realmIdentityStoreMigration)
|
||||
.allowWritesOnUiThread(true)
|
||||
.modules(IdentityRealmModule())
|
||||
.build()
|
||||
|
@ -20,13 +20,20 @@ import io.realm.DynamicRealm
|
||||
import io.realm.RealmMigration
|
||||
import org.matrix.android.sdk.internal.session.identity.db.migration.MigrateIdentityTo001
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal object RealmIdentityStoreMigration : RealmMigration {
|
||||
internal class RealmIdentityStoreMigration @Inject constructor() : RealmMigration {
|
||||
/**
|
||||
* Forces all RealmIdentityStoreMigration instances to be equal
|
||||
* Avoids Realm throwing when multiple instances of the migration are set
|
||||
*/
|
||||
override fun equals(other: Any?) = other is RealmIdentityStoreMigration
|
||||
override fun hashCode() = 3000
|
||||
|
||||
const val IDENTITY_STORE_SCHEMA_VERSION = 1L
|
||||
val schemaVersion = 1L
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
Timber.v("Migrating Realm Identity from $oldVersion to $newVersion")
|
||||
Timber.d("Migrating Realm Identity from $oldVersion to $newVersion")
|
||||
|
||||
if (oldVersion < 1) MigrateIdentityTo001(realm).perform()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user