From 7d5072b529f654aea7552fbe28d4f3db42844fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Mon, 14 May 2018 22:13:08 +0200 Subject: [PATCH] Fix exams sync (#108) --- app/build.gradle | 2 +- .../wulkanowy/data/db/dao/DbHelper.java | 2 ++ .../wulkanowy/data/db/dao/entities/Exam.java | 4 +++- .../data/db/dao/migrations/Migration27.java | 24 +++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/io/github/wulkanowy/data/db/dao/migrations/Migration27.java diff --git a/app/build.gradle b/app/build.gradle index b44353486..d973c8e4e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,7 +91,7 @@ play { } greendao { - schemaVersion 26 + schemaVersion 27 generateTests = true } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/DbHelper.java b/app/src/main/java/io/github/wulkanowy/data/db/dao/DbHelper.java index 07307e529..8aa9b1dfb 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/DbHelper.java +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/DbHelper.java @@ -18,6 +18,7 @@ import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.data.db.dao.entities.DaoMaster; import io.github.wulkanowy.data.db.dao.migrations.Migration23; import io.github.wulkanowy.data.db.dao.migrations.Migration26; +import io.github.wulkanowy.data.db.dao.migrations.Migration27; import io.github.wulkanowy.data.db.shared.SharedPrefContract; import io.github.wulkanowy.di.annotations.ApplicationContext; import io.github.wulkanowy.di.annotations.DatabaseInfo; @@ -76,6 +77,7 @@ public class DbHelper extends DaoMaster.OpenHelper { List migrations = new ArrayList<>(); migrations.add(new Migration23()); migrations.add(new Migration26()); + migrations.add(new Migration27()); // Sorting just to be safe, in case other people add migrations in the wrong order. Comparator migrationComparator = new Comparator() { diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/entities/Exam.java b/app/src/main/java/io/github/wulkanowy/data/db/dao/entities/Exam.java index 076846e11..543b68597 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/entities/Exam.java +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/entities/Exam.java @@ -4,13 +4,15 @@ import org.greenrobot.greendao.DaoException; import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Generated; import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Index; import org.greenrobot.greendao.annotation.Property; import java.io.Serializable; @Entity( nameInDb = "Exams", - active = true + active = true, + indexes = {@Index(value = "dayId,entryDate,subjectAndGroup,type,teacher", unique = true)} ) public class Exam implements Serializable { diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/migrations/Migration27.java b/app/src/main/java/io/github/wulkanowy/data/db/dao/migrations/Migration27.java new file mode 100644 index 000000000..5c8c82f1d --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/migrations/Migration27.java @@ -0,0 +1,24 @@ +package io.github.wulkanowy.data.db.dao.migrations; + +import org.greenrobot.greendao.database.Database; + +import io.github.wulkanowy.api.Vulcan; +import io.github.wulkanowy.data.db.dao.DbHelper; +import io.github.wulkanowy.data.db.dao.entities.ExamDao; +import io.github.wulkanowy.data.db.shared.SharedPrefContract; + +public class Migration27 implements DbHelper.Migration { + + @Override + public Integer getVersion() { + return 27; + } + + @Override + public void runMigration(Database db, SharedPrefContract sharedPref, Vulcan vulcan) throws Exception { + ExamDao.dropTable(db, true); + ExamDao.createTable(db, true); + + db.execSQL("UPDATE Weeks SET exams_synced = 0"); + } +}