We are currently using Realm inside our app, but when I try to perform a migration (because we want to delete a Model/class in our database), the Configuration returns some random huge value from the configuration.schemaVersion.
The migration isn't called, and nothing is deleted. The Realm database was called multiple times with let realm = try? Realm(configuration: Realm.compactConfiguration)
I tried to make one Config throughout the app and set it like the following:
let configuration = Realm.compactingConfiguration
Realm.Configuration.defaultConfiguration = configuration
but the large schemaVersion still appears, and the code doesn't go inside the migrationBlock
extension Realm {
public static var compactConfiguration: Configuration {
get {
// Realm is compacted on the first open if the configuration block conditions were met.
// Compacting when size is greater than 50MB (arbitrary amount, database size should be
// around 2.6MB, so should not reach 50MB)
let currentSchemaVersion: UInt64 = 1
var configuration = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < currentSchemaVersion) {
migration.deleteData(forType: Office.className())
}
})
configuration.deleteRealmIfMigrationNeeded = true
return configuration
}
}
}
Does anyone know what is going on? I expected the versionScheme to be 0 since it was never set before.