Skip to content

Commit

Permalink
Fix db schema migration and run it for affected users
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasrohloff committed Aug 27, 2018
1 parent 9aca492 commit 3b520b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,34 @@ public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
}

if (oldVersion == 2) {
schema.create("Document")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("title", String.class)
.addField("description", String.class)
.addRealmListField("tags", String.class)
.addField("isPublic", boolean.class)
.addRealmListField("courseIds", String.class);
// Document and DocumentLocalization were not added for some user,
// therefore a fix was provided with the next version.

schema.create("DocumentLocalization")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("title", String.class)
.addField("description", String.class)
.addField("language", String.class)
.addField("revision", int.class)
.addField("fileUrl", String.class)
.addField("documentId", String.class);
oldVersion++;
}

if (oldVersion == 3) {
// This DB version only fixes the last one.
if (!schema.contains("Document")) {
schema.create("Document")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("title", String.class)
.addField("description", String.class)
.addRealmListField("tags", String.class)
.addField("isPublic", boolean.class)
.addRealmListField("courseIds", String.class);
}

if (!schema.contains("DocumentLocalization")) {
schema.create("DocumentLocalization")
.addField("id", String.class, FieldAttribute.PRIMARY_KEY)
.addField("title", String.class)
.addField("description", String.class)
.addField("language", String.class)
.addField("revision", int.class)
.addField("fileUrl", String.class)
.addField("documentId", String.class);
}

oldVersion++;
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
versionCode = 44

xikoloApiVersion = 3
realmSchemaVersion = 3
realmSchemaVersion = 4
}
repositories {
jcenter()
Expand Down

0 comments on commit 3b520b3

Please sign in to comment.