[Mobidziennik/Web] Add attendance migration.

This commit is contained in:
Kuba Szczodrzyński 2021-02-26 23:24:37 +01:00
parent 530034d7da
commit 7aaefa977b
2 changed files with 28 additions and 2 deletions

View File

@ -43,7 +43,7 @@ import pl.szczodrzynski.edziennik.data.db.migration.*
LibrusLesson::class,
TimetableManual::class,
Metadata::class
], version = 90)
], version = 91)
@TypeConverters(
ConverterTime::class,
ConverterDate::class,
@ -175,7 +175,8 @@ abstract class AppDb : RoomDatabase() {
Migration87(),
Migration88(),
Migration89(),
Migration90()
Migration90(),
Migration91()
).allowMainThreadQueries().build()
}
}

View File

@ -0,0 +1,25 @@
/*
* 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 Migration91 : Migration(90, 91) {
override fun migrate(database: SupportSQLiteDatabase) {
// get all profiles using Vulcan/Hebe
database.execSQL("CREATE TABLE _91_ids (id INTEGER NOT NULL);")
database.execSQL("INSERT INTO _91_ids SELECT profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 1;")
// force attendance sync - mobidziennik
// after enabling counting the e-attendance to statistics
database.execSQL("DELETE FROM endpointTimers WHERE profileId IN (SELECT id FROM _91_ids) AND endpointId = 2050;")
database.execSQL("UPDATE attendances SET attendanceIsCounted = 1 WHERE profileId IN (SELECT id FROM _91_ids);")
database.execSQL("UPDATE attendances SET attendanceBaseType = 2 WHERE profileId IN (SELECT id FROM _91_ids) AND attendanceTypeSymbol = ?;",
arrayOf("+ₑ"))
database.execSQL("DROP TABLE _91_ids;")
}
}