Create a gist now

Instantly share code, notes, and snippets.

public class Migration implements RealmMigration
{
@Override
public void migrate (DynamicRealm realm, long oldVersion, long newVersion)
{
RealmSchema schema = realm.getSchema();
if ( oldVersion == 1 )
{
RealmObjectSchema recipeSchema = schema.get( "Recipe" );
recipeSchema.addField( RecipeFields.NUMBER_OF_STARS, Integer.class )
.transform( new RealmObjectSchema.Function()
{
@Override
public void apply (DynamicRealmObject obj)
{
obj.setInt( RecipeFields.NUMBER_OF_STARS, 5 );
}
} );
oldVersion++;
}
if ( oldVersion == 2 )
{
RealmObjectSchema recipeSchema = schema.get( "Recipe" );
recipeSchema.addField( RecipeFields.IS_YUMMY, boolean.class );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment