Created
March 7, 2017 19:30
-
-
Save adavis/d3951ced45ef677ba9acbd87c042e7c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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