parent
5019040269
commit
c43600ba25
Binary file not shown.
@ -0,0 +1,63 @@ |
||||
package net.pokeranalytics.android.model.migrations |
||||
|
||||
import io.realm.DynamicRealm |
||||
import io.realm.RealmMigration |
||||
import timber.log.Timber |
||||
|
||||
|
||||
class PokerAnalyticsMigration : RealmMigration { |
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { |
||||
|
||||
// DynamicRealm exposes an editable schema |
||||
val schema = realm.schema |
||||
|
||||
var currentVersion = oldVersion.toInt() |
||||
Timber.d("*** migrate from $oldVersion to $newVersion") |
||||
|
||||
// Migrate to version 1: Add a new class. |
||||
// Example: |
||||
// public Person extends RealmObject { |
||||
// private String name; |
||||
// private int age; |
||||
// // getters and setters left out for brevity |
||||
// } |
||||
/* |
||||
if (currentVersion == 0) { |
||||
Timber.d("*** Running migration 1") |
||||
schema.get("Session")!! |
||||
.addField("isUpdating", Boolean::class.java) |
||||
currentVersion++ |
||||
} |
||||
*/ |
||||
|
||||
// Migrate to version 2: Add a primary key + object references |
||||
// Example: |
||||
// public Person extends RealmObject { |
||||
// private String name; |
||||
// @PrimaryKey |
||||
// private int age; |
||||
// private Dog favoriteDog; |
||||
// private RealmList<Dog> dogs; |
||||
// // getters and setters left out for brevity |
||||
// } |
||||
/* |
||||
if (currentVersion == 1) { |
||||
schema.get("Person")!! |
||||
.addField("id", Long::class.javaPrimitiveType!!, FieldAttribute.PRIMARY_KEY) |
||||
.addRealmObjectField("favoriteDog", schema.get("Dog")!!) |
||||
.addRealmListField("dogs", schema.get("Dog")!!) |
||||
currentVersion++ |
||||
} |
||||
*/ |
||||
|
||||
} |
||||
|
||||
override fun equals(other: Any?): Boolean { |
||||
return other is RealmMigration |
||||
} |
||||
|
||||
override fun hashCode(): Int { |
||||
return RealmMigration::javaClass.hashCode() |
||||
} |
||||
} |
||||
Loading…
Reference in new issue