AutomaticSchemaMigration

fun fun interface AutomaticSchemaMigration : RealmMigration

A realm migration that performs automatic schema migration and allows additional custom migration of data.

The automatic schema migration will not change data for objects and properties that have not been affected by the migration. But properties that have changed configuration (name or type) will be initialized with default values in the migrated realm and data has to be moved manually. The migrate callback provides access to the previous and the migrated realm through a dynamic (string based) API that allow such transformations. Examples are:

  • Merging, transforming and splitting property values

  • Renaming a property

  • Changing type of a property

Transformation like these can be done through MigrationContext.enumerate that iterates all objects of a certain type and provides access to the old and new instance of an object. Some example are given in the documentation of MigrationContext.enumerate.

Types

MigrationContext
Link copied to clipboard
interface MigrationContext
A data migration context providing access to the realm before and after an AutomaticSchemaMigration.

Functions

migrate
Link copied to clipboard
abstract fun migrate(migrationContext: AutomaticSchemaMigration.MigrationContext)
Method called when the schema of the realm has changed.