Migrations - Android SDK¶
A migration transforms an existing realm and its objects from its current Realm Schema version to a newer one. Application data models typically change over time to accommodate new requirements and features. Migrations give you the flexibility to automatically update your existing application data whenever a client application upgrades to a newer version.
A synced migration is a migration for a realm that automatically Syncs with another remote realm. Realm Database automatically handles all synced schema migrations and does not allow you to specify a migration function.
Synced realms represent multiple end users and devices that will likely not all immediately update to the most recent version of an application. MongoDB Realm ensures that synced schema changes are backwards compatible, which means that client applications that have not updated to the most recent version can still sync with clients that are using the most recent version.
MongoDB Realm handles synced migrations using the following framework:
MongoDB Realm ignores any schema version set by the client application.
MongoDB Realm throws an error if the realm configuration includes a local migration function.
MongoDB Realm automatically applies additive changes, such as a new class or class property.
MongoDB Realm does not delete removed fields from the database, but ignores them in future read operations. MongoDB Realm includes deleted properties in new objects with a default value that depends on whether or not the property was required:
MongoDB Realm prevents modifications to an existing property other than delete operations. Modifications that synced realms do not support include:
- A migration transforms an existing realm and its objects from its current schema version to a later one.
- MongoDB Realm allows you to specify migration functions for local migrations, i.e. migrations where the realm is not synced with MongoDB Realm.
- MongoDB Realm automatically handles synced migration, i.e. migrations where the realm is synced. MongoDB Realm does not allow migration functions for such migrations.