Commit 667f5518 authored by Robert Hitt's avatar Robert Hitt

Fixed Realm migration issue

parent 0be851a1
Pipeline #1943 passed with stages
in 2 minutes and 55 seconds
......@@ -16,6 +16,7 @@ out/
# Gradle files
.gradle/
build/
app/release/
# Local configuration file (sdk path, etc)
local.properties
......
......@@ -26,8 +26,8 @@ android {
applicationId "srct.whatsopen"
minSdkVersion 16
targetSdkVersion 26
versionCode 5
versionName "1.0.4"
versionCode 6
versionName "1.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
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,14 +6,13 @@ 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.BuildConfig;
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;
......@@ -37,9 +36,7 @@ public class MyApplication extends Application {
// Default Realm config. Might want to change this later
Realm.init(this);
RealmConfiguration realmConfig = new RealmConfiguration.Builder()
.name("default.realm")
.schemaVersion(0)
.migration(new Migration())
.deleteRealmIfMigrationNeeded()
.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