Fix db upgrade from previous version

This commit is contained in:
SpiritCroc 2020-07-17 16:23:36 +02:00
parent 1d1267ea6a
commit 969f3202de

View file

@ -384,23 +384,29 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi
private fun migrateTo8(realm: DynamicRealm) { private fun migrateTo8(realm: DynamicRealm) {
Timber.d("Step 7 -> 8") Timber.d("Step 7 -> 8")
realm.schema.create("MyDeviceLastSeenInfoEntity") try {
.addField(MyDeviceLastSeenInfoEntityFields.DEVICE_ID, String::class.java) realm.schema.create("MyDeviceLastSeenInfoEntity")
.addPrimaryKey(MyDeviceLastSeenInfoEntityFields.DEVICE_ID) .addField(MyDeviceLastSeenInfoEntityFields.DEVICE_ID, String::class.java)
.addField(MyDeviceLastSeenInfoEntityFields.DISPLAY_NAME, String::class.java) .addPrimaryKey(MyDeviceLastSeenInfoEntityFields.DEVICE_ID)
.addField(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_IP, String::class.java) .addField(MyDeviceLastSeenInfoEntityFields.DISPLAY_NAME, String::class.java)
.addField(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_TS, Long::class.java) .addField(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_IP, String::class.java)
.setNullable(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_TS, true) .addField(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_TS, Long::class.java)
.setNullable(MyDeviceLastSeenInfoEntityFields.LAST_SEEN_TS, true)
} catch (failure: Throwable) {
}
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
realm.schema.get("DeviceInfoEntity") try {
?.addField(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, Long::class.java) realm.schema.get("DeviceInfoEntity")
?.setNullable(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, true) ?.addField(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, Long::class.java)
?.transform { deviceInfoEntity -> ?.setNullable(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, true)
tryThis { ?.transform { deviceInfoEntity ->
deviceInfoEntity.setLong(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, now) tryThis {
deviceInfoEntity.setLong(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, now)
}
} }
} } catch (failure: Throwable) {
}
} }
// Fixes duplicate devices in UserEntity#devices // Fixes duplicate devices in UserEntity#devices