Commit 0be851a1 authored by Robert Hitt's avatar Robert Hitt

Added Realm migration

parent 506c0f8a
Pipeline #1942 passed with stages
in 2 minutes and 55 seconds
package srct.whatsopen;
import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmObjectSchema;
import io.realm.RealmSchema;
import srct.whatsopen.model.Location;
public class Migration implements RealmMigration {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
if(oldVersion == -1) {
RealmObjectSchema facilitySchema = schema.get("Facility");
facilitySchema
.renameField("mName", "name")
.renameField("mMainSchedule", "mainSchedule")
.renameField("mSpecialSchedules", "specialSchedules")
.removeField("mLocation")
.addField("location", Location.class);
RealmObjectSchema mainScheduleSchema = schema.get("MainSchedule");
mainScheduleSchema.addField("openTwentyFourHours", Boolean.class);
RealmObjectSchema specialScheduleSchema = schema.get("SpecialSchedule");
specialScheduleSchema.addField("openTwentyFourHours", Boolean.class);
oldVersion++;
}
}
}
......@@ -6,12 +6,14 @@ import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.util.Log;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
import com.squareup.leakcanary.LeakCanary;
import io.fabric.sdk.android.Fabric;
import io.realm.DynamicRealm;
import io.realm.Realm;
import io.realm.RealmConfiguration;
......@@ -34,7 +36,11 @@ public class MyApplication extends Application {
// Default Realm config. Might want to change this later
Realm.init(this);
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
RealmConfiguration realmConfig = new RealmConfiguration.Builder()
.name("default.realm")
.schemaVersion(0)
.migration(new Migration())
.build();
Realm.setDefaultConfiguration(realmConfig);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment