Add disableFormatUpgrade to Realm configuration (#1566)
This commit is contained in:
parent
aed1ea104b
commit
4e6cb299b3
|
@ -6,6 +6,7 @@ X.Y.Z Release notes
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
* Added property `Realm.isClosed` which indicates if a Realm instance is closed or not.
|
* Added property `Realm.isClosed` which indicates if a Realm instance is closed or not.
|
||||||
|
* Added property `disableFormatUpgrade` to the Realm configuration object which disables automatic file format upgrade when opening a Realm file.
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
* None.
|
* None.
|
||||||
|
|
|
@ -307,6 +307,9 @@ Realm.defaultPath;
|
||||||
* what fits in memory, but it is not persistent and will be removed when the last instance
|
* what fits in memory, but it is not persistent and will be removed when the last instance
|
||||||
* is closed.
|
* is closed.
|
||||||
* @property {boolean} [readOnly=false] - Specifies if this Realm should be opened as read-only.
|
* @property {boolean} [readOnly=false] - Specifies if this Realm should be opened as read-only.
|
||||||
|
* @property {boolean} [disableFormatUpgrade=false] - Specifies if this Realm's file format should
|
||||||
|
* be automatically upgraded if it was created with an older version of the Realm library.
|
||||||
|
* If set to `true` and a file format upgrade is required, an error will be thrown instead.
|
||||||
* @property {Array<Realm~ObjectClass|Realm~ObjectSchema>} [schema] - Specifies all the
|
* @property {Array<Realm~ObjectClass|Realm~ObjectSchema>} [schema] - Specifies all the
|
||||||
* object types in this Realm. **Required** when first creating a Realm at this `path`.
|
* object types in this Realm. **Required** when first creating a Realm at this `path`.
|
||||||
* If omitted, the schema will be read from the existing Realm file.
|
* If omitted, the schema will be read from the existing Realm file.
|
||||||
|
|
|
@ -85,6 +85,7 @@ declare namespace Realm {
|
||||||
schemaVersion?: number;
|
schemaVersion?: number;
|
||||||
sync?: Realm.Sync.SyncConfiguration;
|
sync?: Realm.Sync.SyncConfiguration;
|
||||||
deleteRealmIfMigrationNeeded?: boolean;
|
deleteRealmIfMigrationNeeded?: boolean;
|
||||||
|
disableFormatUpgrade?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// object props type
|
// object props type
|
||||||
|
|
|
@ -520,6 +520,12 @@ void RealmClass<T>::constructor(ContextType ctx, ObjectType this_object, size_t
|
||||||
if (!Value::is_undefined(ctx, cache_value)) {
|
if (!Value::is_undefined(ctx, cache_value)) {
|
||||||
config.cache = Value::validated_to_boolean(ctx, cache_value, "_cache");
|
config.cache = Value::validated_to_boolean(ctx, cache_value, "_cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const String disable_format_upgrade_string = "disableFormatUpgrade";
|
||||||
|
ValueType disable_format_upgrade_value = Object::get_property(ctx, object, disable_format_upgrade_string);
|
||||||
|
if (!Value::is_undefined(ctx, disable_format_upgrade_value)) {
|
||||||
|
config.disable_format_upgrade = Value::validated_to_boolean(ctx, disable_format_upgrade_value, "disableFormatUpgrade");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1181,4 +1181,12 @@ module.exports = {
|
||||||
new Realm({schema: schema, deleteRealmIfMigrationNeeded: true, migration: function(oldRealm, newRealm) {}});
|
new Realm({schema: schema, deleteRealmIfMigrationNeeded: true, migration: function(oldRealm, newRealm) {}});
|
||||||
}, "Cannot include 'migration' when 'deleteRealmIfMigrationNeeded' is set.")
|
}, "Cannot include 'migration' when 'deleteRealmIfMigrationNeeded' is set.")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testDisableFileFormatUpgrade: function() {
|
||||||
|
Realm.copyBundledRealmFiles();
|
||||||
|
|
||||||
|
TestCase.assertThrowsContaining(() => {
|
||||||
|
new Realm({ path: 'dates-v3.realm', disableFormatUpgrade: true } );
|
||||||
|
}, 'The Realm file format must be allowed to be upgraded in order to proceed.');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue