diff --git a/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m b/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m index 1f9faf2299..1edc5655ed 100644 --- a/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m +++ b/MatrixSDK/Crypto/Data/Store/MXRealmCryptoStore/MXRealmCryptoStore.m @@ -2143,12 +2143,15 @@ + (BOOL)finaliseMigrationWith:(RLMMigration *)migration oldSchemaVersion:(uint64 MXLogDebug(@"[MXRealmCryptoStore] Make sure MXRealmOlmAccount.cryptoVersion is MXCryptoVersion2"); [migration enumerateObjects:MXRealmOlmAccount.className block:^(RLMObject *oldObject, RLMObject *newObject) { - NSNumber *version; - MXJSONModelSetNumber(version, oldObject[@"cryptoVersion"]); - if (version && version.intValue == 0) - { - MXLogDebug(@"[MXRealmCryptoStore] -> Fix MXRealmOlmAccount.cryptoVersion"); - newObject[@"cryptoVersion"] = @(MXCryptoVersion2); + if (oldSchemaVersion > 12) { + // cryptoVersion available + NSNumber *version; + MXJSONModelSetNumber(version, oldObject[@"cryptoVersion"]); + if (version && version.intValue == 0) + { + MXLogDebug(@"[MXRealmCryptoStore] -> Fix MXRealmOlmAccount.cryptoVersion"); + newObject[@"cryptoVersion"] = @(MXCryptoVersion2); + } } }]; } diff --git a/changelog.d/1282.bugfix b/changelog.d/1282.bugfix new file mode 100644 index 0000000000..54d8f1387b --- /dev/null +++ b/changelog.d/1282.bugfix @@ -0,0 +1 @@ +MXRealmCryptoStore: fix migration from schema < 13 to schema > 16. \ No newline at end of file