public interface RealmMigration
RealmObject, so any
changes to these classes will require a migration.
To support migrations from any previous schemaVersion to the newest, the following pattern is recommended when
writing a migration:
public class CustomMigration implements RealmMigration {
\@Override
public long execute(Realm realm, long schemaVersion) {
if (schemaVersion == 0) {
// Migrate from v0 to v1
schemaVersion++;
}
if (schemaVersion == 0) {
// Migrate from v0 to v1
schemaVersion++;
}
return schemaVersion;
}
}
During development when model classes can change frequently, it is possible to use
Realm.deleteRealm(RealmConfiguration). This will delete the database file and eliminate the need for
any migrations.| Modifier and Type | Method and Description |
|---|---|
long |
execute(Realm realm,
long version)
Performs migration.
|
long execute(Realm realm, long version)
realm - the Realm on which to perform the migration.version - the schemaVersion of the Realm at the start of the migration.