diff --git a/app/build.gradle b/app/build.gradle index b4435348..d973c8e4 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 07307e52..8aa9b1df 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 076846e1..543b6859 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 00000000..5c8c82f1 --- /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"); + } +}