diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt index 18ef60e2..7dbe6ed4 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt @@ -59,18 +59,21 @@ class RealmProvider(private val loadDataInMemory: Boolean = false) { private val realmAppSettingsConfiguration = RealmConfiguration .Builder(schema = setOf(AppSettingsDB::class)) .name("AppSettings") + .deleteRealmDataIfNeeded() // TODO: Remove before going to production ! .loadDataInMemoryIfNeeded() .build() private val realmUploadDBConfiguration = RealmConfiguration .Builder(schema = setOf(UploadDB::class, UploadContainerDB::class, UploadFileDB::class)) .name("Uploads") + .deleteRealmDataIfNeeded() // TODO: Remove before going to production ! .loadDataInMemoryIfNeeded() .build() private fun realmTransfersConfiguration(userId: Int) = RealmConfiguration .Builder(schema = setOf(TransferDB::class, ContainerDB::class, FileDB::class)) .name(transferRealmName(userId)) + .deleteRealmDataIfNeeded() // TODO: Remove before going to production ! .loadDataInMemoryIfNeeded() .build() @@ -79,4 +82,8 @@ class RealmProvider(private val loadDataInMemory: Boolean = false) { private fun RealmConfiguration.Builder.loadDataInMemoryIfNeeded(): RealmConfiguration.Builder { return apply { if (loadDataInMemory) inMemory() } } + + private fun RealmConfiguration.Builder.deleteRealmDataIfNeeded(): RealmConfiguration.Builder { + return apply { if (!loadDataInMemory) deleteRealmIfMigrationNeeded() } + } }