From 36c7bb1127251aeedaa59fd8941b6cbaa1ed2daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Fri, 26 Feb 2021 20:10:52 +0100 Subject: [PATCH] [Vulcan/Hebe] Add full sync migration. --- .../szczodrzynski/edziennik/data/db/AppDb.kt | 5 ++-- .../data/db/migration/Migration90.kt | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration90.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt index aee8e3af..ff101fd0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.kt @@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.* LibrusLesson::class, TimetableManual::class, Metadata::class -], version = 89) +], version = 90) @TypeConverters( ConverterTime::class, ConverterDate::class, @@ -174,7 +174,8 @@ abstract class AppDb : RoomDatabase() { Migration86(), Migration87(), Migration88(), - Migration89() + Migration89(), + Migration90() ).allowMainThreadQueries().build() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration90.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration90.kt new file mode 100644 index 00000000..7b500525 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration90.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) Kuba SzczodrzyƄski 2021-2-26. + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration90 : Migration(89, 90) { + override fun migrate(database: SupportSQLiteDatabase) { + // get all profiles using Vulcan/Hebe + database.execSQL("CREATE TABLE _90_ids (id INTEGER NOT NULL);") + database.execSQL("INSERT INTO _90_ids SELECT profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 4 AND loginStores.loginStoreMode != 0;") + + // force full sync when updating from <4.6 + database.execSQL("DELETE FROM endpointTimers WHERE profileId IN (SELECT id FROM _90_ids);") + database.execSQL("UPDATE profiles SET empty = 1 WHERE profileId IN (SELECT id FROM _90_ids);") + // remove messages and events to re-download attachments and remove older than current school year + database.execSQL("DELETE FROM messages WHERE profileId IN (SELECT id FROM _90_ids);") + database.execSQL("DELETE FROM events WHERE profileId IN (SELECT id FROM _90_ids) AND eventAddedManually = 0;") + // remove older data + database.execSQL("DELETE FROM notices WHERE profileId IN (SELECT id FROM _90_ids);") + + // fix for v4.5 users who logged in using Vulcan/Web + database.execSQL("UPDATE loginStores SET loginStoreMode = 2 WHERE loginStoreType = 4 AND loginStoreMode = 1;") + + database.execSQL("DROP TABLE _90_ids;") + } +}