How to use the realm.schemaVersion function in realm

To help you get started, we’ve selected a few realm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github realm / realm-js / tests / shared / js / migration-tests.js View on Github external
// invalid migration function
        TestCase.assertThrows(function() {
            new Realm({schema: [], schemaVersion: 2, migration: 'invalid'});
        });

        // migration function exceptions should propogate
        var exception = new Error('expected exception');
        realm = undefined;
        TestCase.assertThrowsException(function() {
            realm = new Realm({schema: [], schemaVersion: 3, migration: function() {
                throw exception;
            }});
        }, exception);
        TestCase.assertEqual(realm, undefined);
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 1);

        // migration function shouldn't run if nothing changes
        realm = new Realm({schema: [Schemas.TestObject], migration: migrationFunction, schemaVersion: 1});
        TestCase.assertEqual(1, count);
        realm.close();

        // migration function should run if only schemaVersion changes
        realm = new Realm({schema: [Schemas.TestObject], migration: function() { count++; }, schemaVersion: 2});
        TestCase.assertEqual(2, count);
        realm.close();
    },
github liu-kaixin / mobile-realm / src / servers / realm / configure.js View on Github external
function configSchema() {
    console.log('初始化 ================> ')
// && DeviceInfo.isEmulator()
    if (__DEV__ && Platform.OS === 'ios') {
        Realm.defaultPath = '/Users/Shared/data/data.realm'
    }
    console.log('Realm.defaultPath:', Realm.defaultPath);
    var next = Realm.schemaVersion(Realm.defaultPath);
    if (next > 0) {
        while (next < schemas.length) {
            const migratedSchema = schemas[next++];
            const migratedRealm = new Realm(migratedSchema);
            migratedRealm.close();
        }
    }
    const getNewSchemas = schemas[schemas.length - 1];
    const realm = new Realm(getNewSchemas);
    // realm.close();
}
github Bit-Nation / BITNATION-Pangea-mobile / src / services / database / index.js View on Github external
export function* factory(customDbPath: string) {
  let databasePath = REALM_PATH;

  if (customDbPath !== '' && typeof customDbPath === 'string') {
    databasePath = customDbPath;
  }

  let nextSchemaIndex = Realm.schemaVersion(databasePath);

  // We must use -1 since our schemas start by 0 and not by one.
  while (nextSchemaIndex < schemas.length - 1) {
    nextSchemaIndex += 1;
    const schema = schemas[nextSchemaIndex];
    const migratedRealm = yield Realm.open({
      path: databasePath,
      schema: schema.schema,
      schemaVersion: schema.schemaVersion,
      migration: schema.migration,
    });
    migratedRealm.close();
  }

  const schema = schemas[schemas.length - 1];
  return yield Realm.open({
github Bit-Nation / BITNATION-Pangea-mobile / src / modules / database / index.js View on Github external
export function* factory(customDbPath: ?string, minVersion: number = 0): Generator<*, *, *> {
  let databasePath = REALM_PATH;

  if (customDbPath !== '' && typeof customDbPath === 'string') {
    databasePath = customDbPath;
  }

  let nextSchemaIndex = Math.max(minVersion - 1, Realm.schemaVersion(databasePath));

  // We must use -1 since our schemas start by 0 and not by one.
  while (nextSchemaIndex < schemas.length - 1) {
    nextSchemaIndex += 1;
    const schema = schemas[nextSchemaIndex];
    const migratedRealm = yield Realm.open({
      path: databasePath,
      schema: schema.schema,
      schemaVersion: schema.schemaVersion,
      migration: schema.migration,
    });
    migratedRealm.close();
  }

  const schema = schemas[schemas.length - 1];
  return yield Realm.open({
github realm / realm-js / tests / js / realm-tests.js View on Github external
testRealmSchemaVersion: function() {
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), -1);
        
        var realm = new Realm({schema: []});
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 0);

        realm = new Realm({schema: [], schemaVersion: 2, path: 'another.realm'});
        TestCase.assertEqual(Realm.schemaVersion('another.realm'), 2);

        var encryptionKey = new Int8Array(64);
        realm = new Realm({schema: [], schemaVersion: 3, path: 'encrypted.realm', encryptionKey: encryptionKey});
        TestCase.assertEqual(Realm.schemaVersion('encrypted.realm', encryptionKey), 3);

        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', encryptionKey, 'extra');
        });
        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', 'asdf');
        });
    },
github realm / realm-js / tests / js / realm-tests.js View on Github external
testRealmSchemaVersion: function() {
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), -1);
        
        var realm = new Realm({schema: []});
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 0);

        realm = new Realm({schema: [], schemaVersion: 2, path: 'another.realm'});
        TestCase.assertEqual(Realm.schemaVersion('another.realm'), 2);

        var encryptionKey = new Int8Array(64);
        realm = new Realm({schema: [], schemaVersion: 3, path: 'encrypted.realm', encryptionKey: encryptionKey});
        TestCase.assertEqual(Realm.schemaVersion('encrypted.realm', encryptionKey), 3);

        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', encryptionKey, 'extra');
        });
        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', 'asdf');
        });
    },
github realm / realm-js / tests / js / encryption-tests.js View on Github external
TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', 'asdf');
        });
    },
github realm / realm-js / tests / js / realm-tests.js View on Github external
TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', encryptionKey, 'extra');
        });
        TestCase.assertThrows(function() {
github realm / realm-js / tests / js / realm-tests.js View on Github external
testRealmSchemaVersion: function() {
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), -1);
        
        var realm = new Realm({schema: []});
        TestCase.assertEqual(Realm.schemaVersion(Realm.defaultPath), 0);

        realm = new Realm({schema: [], schemaVersion: 2, path: 'another.realm'});
        TestCase.assertEqual(Realm.schemaVersion('another.realm'), 2);

        var encryptionKey = new Int8Array(64);
        realm = new Realm({schema: [], schemaVersion: 3, path: 'encrypted.realm', encryptionKey: encryptionKey});
        TestCase.assertEqual(Realm.schemaVersion('encrypted.realm', encryptionKey), 3);

        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', encryptionKey, 'extra');
        });
        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', 'asdf');
        });
    },
github realm / realm-js / tests / js / encryption-tests.js View on Github external
testRealmSchemaVersion: function() {
        var encryptionKey = new Int8Array(64);
        var realm = new Realm({schema: [], schemaVersion: 3, path: 'encrypted.realm', encryptionKey: encryptionKey});
        TestCase.assertEqual(realm.schemaVersion, 3);
        TestCase.assertEqual(Realm.schemaVersion('encrypted.realm', encryptionKey), 3);

        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', encryptionKey, 'extra');
        });
        TestCase.assertThrows(function() {
            Realm.schemaVersion('encrypted.realm', 'asdf');
        });
    },