Skip to content

Commit

Permalink
RDART-1066: Make schema mode for synchronized realms explicit (#1748)
Browse files Browse the repository at this point in the history
* Make schema mode for synchronized realms explicit

* Add changelog
  • Loading branch information
nirinchev authored Jul 29, 2024
1 parent 633654d commit 28e0e5a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 86 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* None

### Fixed
* None
* Fixed an issue where creating a flexible sync configuration with an embedded object not referenced by any top-level object would throw a "No such table" exception with no meaningful information about the issue. Now a `RealmException` will be thrown that includes the offending object name, as well as more precise text for what the root cause of the error is. (PR [#1748](https://github.com/realm/realm-dart/pull/1748))

### Compatibility
* Realm Studio: 15.0.0 or later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ConfigHandle extends HandleBase<realm_config> {
} else if (config is InMemoryConfiguration) {
realmLib.realm_config_set_in_memory(configHandle.pointer, true);
} else if (config is FlexibleSyncConfiguration) {
realmLib.realm_config_set_schema_mode(configHandle.pointer, realm_schema_mode.RLM_SCHEMA_MODE_ADDITIVE_DISCOVERED);
realmLib.realm_config_set_schema_mode(configHandle.pointer, realm_schema_mode.RLM_SCHEMA_MODE_ADDITIVE_EXPLICIT);
final syncConfigPtr = realmLib.realm_flx_sync_config_new((config.user.handle as UserHandle).pointer).raiseLastErrorIfNull();
try {
realmLib.realm_sync_config_set_session_stop_policy(syncConfigPtr, config.sessionStopPolicy.index);
Expand Down
28 changes: 14 additions & 14 deletions packages/realm_dart/test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ void main() {

test('Configuration inMemory can not be readOnly', () {
Configuration config = Configuration.inMemory([Car.schema]);
final realm = getRealm(config);

expect(() => getRealm(config), returnsNormally);

expect(() {
config = Configuration.local([Car.schema], isReadOnly: true);
Expand All @@ -178,7 +179,7 @@ void main() {

test('Configuration - FIFO files fallback path', () {
Configuration config = Configuration.local([Car.schema], fifoFilesFallbackPath: "./fifo_folder");
final realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);
});

test('Configuration.operator== equal configs', () {
Expand Down Expand Up @@ -344,14 +345,13 @@ void main() {
}
});

final realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);

expect(callbackEx, isNotNull);
expect(callbackEx.toString(), contains('The Realm is already in a write transaction'));
});

test("Configuration.initialDataCallback destroys objects after callback", () {
Exception? callbackEx;
late RealmResults<Person> people;
late Person george;
final config = Configuration.local([Person.schema], initialDataCallback: (realm) {
Expand All @@ -377,7 +377,7 @@ void main() {
return false;
});

final realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);
expect(invoked, true);
});

Expand All @@ -404,7 +404,7 @@ void main() {
return false;
});

final realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);
expect(invoked, 1);

// Try to open the Realm again - callback should not be invoked because the first Realm
Expand All @@ -420,7 +420,7 @@ void main() {
return totalSize > 0;
});

final realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);
expect(invoked, true);
});

Expand All @@ -442,7 +442,7 @@ void main() {
}
}

for (var shouldCompact in [true, false]) {
for (var shouldCompact in [true, false]) {
test('Configuration.shouldCompact when return $shouldCompact triggers compaction', () async {
var config = Configuration.local([Person.schema]);

Expand Down Expand Up @@ -484,7 +484,7 @@ void main() {
return false;
});

final realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);
expect(invoked, isTrue);
});

Expand All @@ -511,11 +511,11 @@ void main() {
final app = App(appConfig);
final user = await app.logIn(Credentials.emailPassword(testUsername, testPassword));
var customPath = path.join(
path.dirname(Configuration.defaultStoragePath),
path.basename('my-custom-realm-name.realm'),
platformUtil.createTempPathSync(),
'my-custom-realm-name.realm',
);
final config = Configuration.flexibleSync(user, getSyncSchema(), path: customPath);
var realm = getRealm(config);
expect(() => getRealm(config), returnsNormally);
});

baasTest('Configuration.disconnectedSync', (appConfig) async {
Expand Down Expand Up @@ -613,9 +613,9 @@ void main() {
var config = Configuration.local([Dog.schema, Person.schema], maxNumberOfActiveVersions: 2);

final realm = getRealm(config);
final frozen1 = realm.freeze();
realm.freeze();
realm.write(() => realm.add(Dog("Foxi1")));
final frozen2 = realm.freeze();
realm.freeze();
realm.write(() => realm.add(Dog("Foxi2")));
expect(() => realm.write(() {}), throws<RealmException>("Number of active versions (3) in the Realm exceeded the limit of 2"));
});
Expand Down
Loading

0 comments on commit 28e0e5a

Please sign in to comment.