Split code into several methods

This commit is contained in:
Benoit Marty 2020-01-03 14:25:19 +01:00
parent c2e7e33050
commit 160927e7b5

View file

@ -31,7 +31,12 @@ internal object AuthRealmMigration : RealmMigration {
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
Timber.d("Migrating Auth Realm from $oldVersion to $newVersion")
if (oldVersion <= 0) {
if (oldVersion <= 0) migrateTo1(realm)
if (oldVersion <= 1) migrateTo2(realm)
if (oldVersion <= 2) migrateTo3(realm)
}
private fun migrateTo1(realm: DynamicRealm) {
Timber.d("Step 0 -> 1")
Timber.d("Create PendingSessionEntity")
@ -48,7 +53,7 @@ internal object AuthRealmMigration : RealmMigration {
.addField(PendingSessionEntityFields.CURRENT_THREE_PID_DATA_JSON, String::class.java)
}
if (oldVersion <= 1) {
private fun migrateTo2(realm: DynamicRealm) {
Timber.d("Step 1 -> 2")
Timber.d("Add boolean isTokenValid in SessionParamsEntity, with value true")
@ -57,7 +62,7 @@ internal object AuthRealmMigration : RealmMigration {
?.transform { it.set(SessionParamsEntityFields.IS_TOKEN_VALID, true) }
}
if (oldVersion <= 2) {
private fun migrateTo3(realm: DynamicRealm) {
Timber.d("Step 2 -> 3")
Timber.d("Update SessionParamsEntity primary key, to allow several sessions with the same userId")
@ -77,5 +82,4 @@ internal object AuthRealmMigration : RealmMigration {
}
?.addPrimaryKey(SessionParamsEntityFields.SESSION_ID)
}
}
}