-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(DriveMigration): Add drive migration to avoid crash when switchin…
…g users
- Loading branch information
1 parent
2393ad0
commit fde2c48
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/infomaniak/drive/data/cache/DriveMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Infomaniak kDrive - Android | ||
* Copyright (C) 2025 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.drive.data.cache | ||
|
||
import io.realm.DynamicRealm | ||
import io.realm.RealmMigration | ||
|
||
class DriveMigration : RealmMigration { | ||
|
||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { | ||
var oldVersionTemp = oldVersion | ||
|
||
// DynamicRealm exposes an editable schema | ||
val schema = realm.schema | ||
|
||
// Migrated to version 1 | ||
if (oldVersionTemp == 0L) { | ||
|
||
val driveQuotaSchema = schema.create("DriveQuota").apply { | ||
addField("current", Int::class.java) | ||
addField("max", Int::class.java) | ||
isEmbedded = true | ||
} | ||
|
||
val driveQuotasSchema = schema.create("DriveQuotas").apply { | ||
addRealmObjectField("dropbox", driveQuotaSchema) | ||
addRealmObjectField("sharedLink", driveQuotaSchema) | ||
isEmbedded = true | ||
} | ||
|
||
schema["Drive"]?.apply { | ||
if (hasField("_packFunctionality")) removeField("_packFunctionality") | ||
addRealmObjectField("_quotas", driveQuotasSchema) | ||
} | ||
|
||
oldVersionTemp++ | ||
} | ||
} | ||
|
||
companion object { | ||
const val DB_VERSION = 1L // Must be bumped when the schema changes | ||
} | ||
|
||
} |