From b0edcb5407eedbd8c3269582aa1c383228c806b1 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Thu, 17 Sep 2020 16:11:06 +0200 Subject: [PATCH 1/9] WiP --- src/js_realm.hpp | 2 ++ tests/js/realm-tests.js | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 5a08f4a58a..73a5887b18 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -486,6 +486,8 @@ template bool RealmClass::get_realm_config(ContextType ctx, size_t argc, const ValueType arguments[], realm::Realm::Config& config, ObjectDefaultsMap& defaults, ConstructorMap& constructors) { bool schema_updated = false; + std::cout << "Blah" << std::endl; + if (argc > 1) { throw std::runtime_error("Invalid arguments when constructing 'Realm'"); } diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index 134bbe304e..3733bbe915 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -1609,6 +1609,58 @@ module.exports = { }); }, + testR2: function() { + if (!global.enableSyncTests) { + return; + } + + const schema = [{ + name: 'TestObject', + properties: { + prop0: 'string', + prop1: 'int', + } + }]; + + var realm = new Realm({schema: schema}); + + realm.write(function() { + realm.create('TestObject', ['stringValue', 1]); + }); + + realm.close(); + + + realm = new Realm({schema: schema, deleteRealmIfMigrationNeeded: true, schemaVersion: 1, migration: undefined }); + + + // 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"' }, + // }; + + // const realm = new Realm(config); + // const path = realm.path; + // realm.close(); + + // return fs.exists(path) + // .then(pathExistBeforeDelete => { + // TestCase.assertTrue(pathExistBeforeDelete); + // Realm.deleteFile(config); + + // return fs.exists(path) + // }) + // .then(pathExistAfterDelete => { + // TestCase.assertFalse(pathExistAfterDelete); + // }); + // }); + }, + testRealmDeleteRealmIfMigrationNeededVersionChanged: function() { const schema = [{ name: 'TestObject', From a08fbb9cecc9a8c33ede72597f9e4b18475db9c4 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Mon, 21 Sep 2020 13:02:48 +0200 Subject: [PATCH 2/9] Disallow deleteRealmIfMigrationNeeded in Realm config when sync is enabled --- src/js_realm.hpp | 5 ++-- tests/js/realm-tests.js | 57 ++++++++++------------------------------- 2 files changed, 16 insertions(+), 46 deletions(-) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 73a5887b18..0f20f83ccd 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -486,8 +486,6 @@ template bool RealmClass::get_realm_config(ContextType ctx, size_t argc, const ValueType arguments[], realm::Realm::Config& config, ObjectDefaultsMap& defaults, ConstructorMap& constructors) { bool schema_updated = false; - std::cout << "Blah" << std::endl; - if (argc > 1) { throw std::runtime_error("Invalid arguments when constructing 'Realm'"); } @@ -546,6 +544,9 @@ bool RealmClass::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->partition_value != "") { + throw std::invalid_argument("Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set)."); + } config.schema_mode = SchemaMode::ResetFile; } diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index 3733bbe915..ddf9d1f575 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -1609,56 +1609,25 @@ module.exports = { }); }, - testR2: function() { + testNoMigrationOnSync: function() { if (!global.enableSyncTests) { return; } - const schema = [{ - name: 'TestObject', - properties: { - prop0: 'string', - prop1: 'int', - } - }]; - - var realm = new Realm({schema: schema}); + 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, + }; - realm.write(function() { - realm.create('TestObject', ['stringValue', 1]); + TestCase.assertThrows(function() { + new Realm(config); + }, "Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set)."); }); - - realm.close(); - - - realm = new Realm({schema: schema, deleteRealmIfMigrationNeeded: true, schemaVersion: 1, migration: undefined }); - - - // 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"' }, - // }; - - // const realm = new Realm(config); - // const path = realm.path; - // realm.close(); - - // return fs.exists(path) - // .then(pathExistBeforeDelete => { - // TestCase.assertTrue(pathExistBeforeDelete); - // Realm.deleteFile(config); - - // return fs.exists(path) - // }) - // .then(pathExistAfterDelete => { - // TestCase.assertFalse(pathExistAfterDelete); - // }); - // }); }, testRealmDeleteRealmIfMigrationNeededVersionChanged: function() { From b81f5be5ebdd9d4f9b238444cb3d5679b2870473 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Mon, 21 Sep 2020 13:20:40 +0200 Subject: [PATCH 3/9] Amended changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4754695f4..6c4a30b3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ x.x.x Release notes (yyyy-MM-dd) ### Fixed * Fixed `create(...)` deprecation warning. ([#3243](https://github.com/realm/realm-js/pull/3243)) +* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) ([RJS-755](https://jira.mongodb.org/browse/RJS-755)) ### Compatibility * MongoDB Realm Cloud. From ba7e91b7f0b77f5c2726e5d70dd4db3d98318f46 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Mon, 21 Sep 2020 13:25:28 +0200 Subject: [PATCH 4/9] Updated documentation --- docs/realm.js | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/realm.js b/docs/realm.js index 48824ed7ce..83d5086d51 100644 --- a/docs/realm.js +++ b/docs/realm.js @@ -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: From 357576ef536cb2ded916d924e746c89c9b7499c5 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Mon, 21 Sep 2020 14:31:32 +0200 Subject: [PATCH 5/9] Fixed nullptr segfault --- src/js_realm.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 6eddd3a92f..dea1ff62c3 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -544,9 +544,11 @@ bool RealmClass::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->partition_value != "") { + std::cout << "Bleep" << std::endl; + if (config.sync_config && config.sync_config->partition_value != "") { throw std::invalid_argument("Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set)."); } + std::cout << "Bloop" << std::endl; config.schema_mode = SchemaMode::ResetFile; } From 36b680ec64a5f4b13e043c7b4cfb72baca4b92f8 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Mon, 21 Sep 2020 16:17:57 +0200 Subject: [PATCH 6/9] Debugging cleanup --- src/js_realm.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/js_realm.hpp b/src/js_realm.hpp index dea1ff62c3..67678082d3 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -544,11 +544,9 @@ bool RealmClass::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."); } - std::cout << "Bleep" << std::endl; if (config.sync_config && config.sync_config->partition_value != "") { - throw std::invalid_argument("Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set)."); + throw std::invalid_argument("Cannot set 'deleteRealmIfMigrationNeeded' when sync is enabled ('sync.partitionValue' is set)."); } - std::cout << "Bloop" << std::endl; config.schema_mode = SchemaMode::ResetFile; } From 7be38f52d5b59a529f990b9d08f4e701b5d1d7d2 Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Tue, 22 Sep 2020 09:47:36 +0200 Subject: [PATCH 7/9] Changed changelog according to PR comments --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4a30b3a3..7a3080c391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ x.x.x Release notes (yyyy-MM-dd) ### Fixed * Fixed `create(...)` deprecation warning. ([#3243](https://github.com/realm/realm-js/pull/3243)) -* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) ([RJS-755](https://jira.mongodb.org/browse/RJS-755)) +* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) (RJS-755) ### Compatibility * MongoDB Realm Cloud. From 6accf9beee68762f22ab2ef9b8d3407607f0ec6d Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Tue, 22 Sep 2020 13:17:55 +0200 Subject: [PATCH 8/9] Changed changelog according to PR comments. Again. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3080c391..0526695aa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ x.x.x Release notes (yyyy-MM-dd) ### Fixed * Fixed `create(...)` deprecation warning. ([#3243](https://github.com/realm/realm-js/pull/3243)) -* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) (RJS-755) +* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) ### Compatibility * MongoDB Realm Cloud. From b06cc86c5042f4a2b5d588acefd008d6f2d17add Mon Sep 17 00:00:00 2001 From: Franck Franck Date: Wed, 23 Sep 2020 10:08:14 +0200 Subject: [PATCH 9/9] Fixed test return value according to review comment --- CHANGELOG.md | 2 +- tests/js/realm-tests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0526695aa2..31b48c291e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ x.x.x Release notes (yyyy-MM-dd) ### Fixed * Fixed `create(...)` deprecation warning. ([#3243](https://github.com/realm/realm-js/pull/3243)) -* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) +* Throw error when `deleteRealmIfMigrationNeeded` is requested on a synced realm (incompatible options) ([#3245](https://github.com/realm/realm-js/pull/3245)) ### Compatibility * MongoDB Realm Cloud. diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index ddf9d1f575..4fe39e3652 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -1611,7 +1611,7 @@ module.exports = { testNoMigrationOnSync: function() { if (!global.enableSyncTests) { - return; + return Promise.resolve(); } const appConfig = require('./support/testConfig').integrationAppConfig;