Store lastMessage instead of it's fields in conversation

This commit is contained in:
moezbhatti
2019-11-09 03:43:15 -05:00
parent e720ee9560
commit 335c5757c4
11 changed files with 74 additions and 71 deletions
@@ -25,7 +25,7 @@ import io.realm.RealmMigration
class QkRealmMigration : RealmMigration {
companion object {
const val SCHEMA_VERSION: Long = 7
const val SCHEMA_VERSION: Long = 8
}
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
@@ -92,9 +92,19 @@ class QkRealmMigration : RealmMigration {
version++
}
if (version < newVersion) {
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
if (version == 7L) {
realm.schema.get("Conversation")
?.addRealmObjectField("lastMessage", realm.schema.get("Message"))
?.removeField("count")
?.removeField("date")
?.removeField("snippet")
?.removeField("read")
?.removeField("me")
version++
}
check(version >= newVersion) { "Migration missing from v$oldVersion to v$newVersion" }
}
}