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/ ...@@ -16,6 +16,7 @@ out/
# Gradle files # Gradle files
.gradle/ .gradle/
build/ build/
app/release/
# Local configuration file (sdk path, etc) # Local configuration file (sdk path, etc)
local.properties local.properties
......
...@@ -26,8 +26,8 @@ android { ...@@ -26,8 +26,8 @@ android {
applicationId "srct.whatsopen" applicationId "srct.whatsopen"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 26
versionCode 5 versionCode 6
versionName "1.0.4" versionName "1.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { 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; ...@@ -6,14 +6,13 @@ import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log;
import com.crashlytics.android.BuildConfig;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore; import com.crashlytics.android.core.CrashlyticsCore;
import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.LeakCanary;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
import io.realm.DynamicRealm;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmConfiguration; import io.realm.RealmConfiguration;
...@@ -37,9 +36,7 @@ public class MyApplication extends Application { ...@@ -37,9 +36,7 @@ public class MyApplication extends Application {
// Default Realm config. Might want to change this later // Default Realm config. Might want to change this later
Realm.init(this); Realm.init(this);
RealmConfiguration realmConfig = new RealmConfiguration.Builder() RealmConfiguration realmConfig = new RealmConfiguration.Builder()
.name("default.realm") .deleteRealmIfMigrationNeeded()
.schemaVersion(0)
.migration(new Migration())
.build(); .build();
Realm.setDefaultConfiguration(realmConfig); 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