Skip to content

Instantly share code, notes, and snippets.

@adavis
Created March 7, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adavis/d3951ced45ef677ba9acbd87c042e7c4 to your computer and use it in GitHub Desktop.
Save adavis/d3951ced45ef677ba9acbd87c042e7c4 to your computer and use it in GitHub Desktop.
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