Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow realm migration on synced realms #3245

Merged
merged 10 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ x.x.x Release notes (yyyy-MM-dd)

### Fixed
* Fixed `create<T>(...)` deprecation warning. ([#3243](https://github.com/realm/realm-js/pull/3243))
* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options)

### Compatibility
* MongoDB Realm Cloud.
Expand Down
1 change: 1 addition & 0 deletions docs/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class Realm {
* - `newRealm` - The Realm that uses the latest `schema`, which should be modified as necessary.
* @property {boolean} [deleteRealmIfMigrationNeeded=false] - Specifies if this Realm should be deleted
* if a migration is needed.
* This option is not available on synced realms.
* @property {callback(number, number)} [shouldCompactOnLaunch] - The function called when opening
* a Realm for the first time during the life of a process to determine if it should be compacted
* before being returned to the user. The function takes two arguments:
Expand Down
3 changes: 3 additions & 0 deletions src/js_realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ bool RealmClass<T>::get_realm_config(ContextType ctx, size_t argc, const ValueTy
if (config.schema_mode == SchemaMode::Immutable) {
throw std::invalid_argument("Cannot set 'deleteRealmIfMigrationNeeded' when 'readOnly' is set.");
}
if (config.sync_config && config.sync_config->partition_value != "") {
throw std::invalid_argument("Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set).");
}

config.schema_mode = SchemaMode::ResetFile;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/js/realm-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,27 @@ module.exports = {
});
},

testNoMigrationOnSync: function() {
if (!global.enableSyncTests) {
return;
fronck marked this conversation as resolved.
Show resolved Hide resolved
}

const appConfig = require('./support/testConfig').integrationAppConfig;
let app = new Realm.App(appConfig);
return app.logIn(Realm.Credentials.anonymous())
.then(user => {
const config = {
schema: [schemas.TestObject],
sync: {user, partitionValue: '"Lolo"' },
deleteRealmIfMigrationNeeded: true,
};

TestCase.assertThrows(function() {
new Realm(config);
}, "Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set).");
});
},

testRealmDeleteRealmIfMigrationNeededVersionChanged: function() {
const schema = [{
name: 'TestObject',
Expand Down