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 b7d0c3f3..06bdc578 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 @@ -5,15 +5,12 @@ import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase import androidx.room.TypeConverters -import androidx.room.migration.Migration -import androidx.sqlite.db.SupportSQLiteDatabase import pl.szczodrzynski.edziennik.config.db.ConfigDao import pl.szczodrzynski.edziennik.config.db.ConfigEntry -import pl.szczodrzynski.edziennik.crc32 import pl.szczodrzynski.edziennik.data.db.converter.* import pl.szczodrzynski.edziennik.data.db.dao.* import pl.szczodrzynski.edziennik.data.db.entity.* -import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.data.db.migration.* @Database(entities = [ Grade::class, @@ -89,769 +86,6 @@ abstract class AppDb : RoomDatabase() { @Volatile private var instance: AppDb? = null private val LOCK = Any() - private val MIGRATION_11_12: Migration = object : Migration(11, 12) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("PRAGMA foreign_keys=off;") - database.execSQL("ALTER TABLE teams RENAME TO _teams_old;") - database.execSQL("CREATE TABLE teams (profileId INTEGER NOT NULL, teamId INTEGER NOT NULL, teamType INTEGER NOT NULL, teamName TEXT, teamTeacherId INTEGER NOT NULL, PRIMARY KEY(profileId, teamId));") - database.execSQL("INSERT INTO teams (profileId, teamId, teamType, teamName, teamTeacherId) SELECT profileId, teamId, teamType, teamName, teacherId FROM _teams_old;") - database.execSQL("DROP TABLE _teams_old;") - database.execSQL("PRAGMA foreign_keys=on;") - } - } - private val MIGRATION_12_13: Migration = object : Migration(12, 13) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE lessonChanges ADD lessonChangeWeekDay INTEGER NOT NULL DEFAULT -1;") - } - } - private val MIGRATION_13_14: Migration = object : Migration(13, 14) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE loginStores (loginStoreId INTEGER NOT NULL, loginStoreType INTEGER NOT NULL, loginStoreData TEXT, PRIMARY KEY(loginStoreId));") - } - } - private val MIGRATION_14_15: Migration = object : Migration(14, 15) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades RENAME TO _grades_old;") - database.execSQL("CREATE TABLE `grades` (\n" + - "\t`profileId`\tINTEGER NOT NULL,\n" + - "\t`gradeId`\tINTEGER NOT NULL,\n" + - "\t`gradeDescription`\tTEXT,\n" + - "\t`gradeName`\tTEXT,\n" + - "\t`gradeValue`\tREAL NOT NULL,\n" + - "\t`gradeWeight`\tREAL NOT NULL,\n" + - "\t`gradeSemester`\tINTEGER NOT NULL,\n" + - "\t`gradeType`\tINTEGER NOT NULL,\n" + - "\t`teacherId`\tINTEGER NOT NULL,\n" + - "\t`categoryId`\tINTEGER NOT NULL,\n" + - "\t`subjectId`\tINTEGER NOT NULL,\n" + - "\tPRIMARY KEY(`profileId`,`gradeId`)\n" + - ");") - database.execSQL("INSERT INTO grades\n" + - " SELECT *\n" + - " FROM _grades_old;") - database.execSQL("DROP TABLE _grades_old;") - database.execSQL("CREATE INDEX index_grades_profileId ON grades (profileId);") - } - } - private val MIGRATION_15_16: Migration = object : Migration(15, 16) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE profiles (" + - "profileId INTEGER NOT NULL, " + - "name TEXT, " + - "subname TEXT, " + - "image TEXT, " + - "syncEnabled INTEGER NOT NULL, " + - "syncNotifications INTEGER NOT NULL, " + - "enableSharedEvents INTEGER NOT NULL, " + - "countInSeconds INTEGER NOT NULL, " + - "loggedIn INTEGER NOT NULL, " + - "empty INTEGER NOT NULL, " + - "studentNameLong TEXT, " + - "studentNameShort TEXT, " + - "studentNumber INTEGER NOT NULL, " + - "studentData TEXT, " + - "registration INTEGER NOT NULL, " + - "gradeColorMode INTEGER NOT NULL, " + - "agendaViewType INTEGER NOT NULL, " + - "currentSemester INTEGER NOT NULL, " + - "attendancePercentage REAL NOT NULL, " + - "dateSemester1Start TEXT, " + - "dateSemester2Start TEXT, " + - "dateYearEnd TEXT, " + - "luckyNumberEnabled INTEGER NOT NULL, " + - "luckyNumber INTEGER NOT NULL, " + - "luckyNumberDate TEXT, " + - "loginStoreId INTEGER NOT NULL, " + - "PRIMARY KEY(profileId));") - } - } - private val MIGRATION_16_17: Migration = object : Migration(16, 17) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE profiles ADD archived INTEGER NOT NULL DEFAULT 0;") - database.execSQL("ALTER TABLE teams ADD teamCode TEXT;") - } - } - private val MIGRATION_17_18: Migration = object : Migration(17, 18) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE events ADD eventBlacklisted INTEGER NOT NULL DEFAULT 0;") - } - } - private val MIGRATION_18_19: Migration = object : Migration(18, 19) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades ADD gradeClassAverage REAL NOT NULL DEFAULT -1;") - } - } - private val MIGRATION_19_20: Migration = object : Migration(19, 20) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE luckyNumbers (" + - "profileId INTEGER NOT NULL, " + - "luckyNumberDate TEXT NOT NULL, " + - "luckyNumber INTEGER NOT NULL, " + - "PRIMARY KEY(profileId, luckyNumberDate));") - } - } - private val MIGRATION_20_21: Migration = object : Migration(20, 21) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades ADD gradeCategory TEXT") - database.execSQL("ALTER TABLE grades ADD gradeColor INTEGER NOT NULL DEFAULT -1") - database.execSQL("DROP TABLE gradeCategories") - } - } - private val MIGRATION_21_22: Migration = object : Migration(21, 22) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE eventTypes (" + - "profileId INTEGER NOT NULL, " + - "eventType INTEGER NOT NULL, " + - "eventTypeName TEXT, " + - "eventTypeColor INTEGER NOT NULL, " + - "PRIMARY KEY(profileId, eventType));") - } - } - private val MIGRATION_22_23: Migration = object : Migration(22, 23) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades RENAME TO _grades_old;") - database.execSQL("CREATE TABLE `grades` (\n" + - "\t`profileId`\tINTEGER NOT NULL,\n" + - "\t`gradeId`\tINTEGER NOT NULL,\n" + - "\t`gradeCategory`\tTEXT,\n" + - "\t`gradeColor`\tINTEGER NOT NULL DEFAULT -1,\n" + - "\t`gradeDescription`\tTEXT,\n" + - "\t`gradeName`\tTEXT,\n" + - "\t`gradeValue`\tREAL NOT NULL,\n" + - "\t`gradeWeight`\tREAL NOT NULL,\n" + - "\t`gradeSemester`\tINTEGER NOT NULL,\n" + - "\t`gradeClassAverage`\tREAL NOT NULL DEFAULT -1,\n" + - "\t`gradeType`\tINTEGER NOT NULL,\n" + - "\t`teacherId`\tINTEGER NOT NULL,\n" + - "\t`subjectId`\tINTEGER NOT NULL,\n" + - "\tPRIMARY KEY(`profileId`,`gradeId`)\n" + - ");") - database.execSQL("DROP INDEX index_grades_profileId") - database.execSQL("CREATE INDEX `index_grades_profileId` ON `grades` (\n" + - "\t`profileId`\n" + - ");") - database.execSQL("INSERT INTO grades (profileId, gradeId, gradeDescription, gradeName, gradeValue, gradeWeight, gradeSemester, gradeType, teacherId, subjectId, gradeClassAverage, gradeCategory, gradeColor) SELECT profileId, gradeId, gradeDescription, gradeName, gradeValue, gradeWeight, gradeSemester, gradeType, teacherId, subjectId, gradeClassAverage, gradeCategory, gradeColor FROM _grades_old;") - database.execSQL("DROP TABLE _grades_old;") - database.execSQL("ALTER TABLE attendances RENAME TO _attendances_old;") - database.execSQL("CREATE TABLE `attendances` (\n" + - "\t`profileId`\tINTEGER NOT NULL,\n" + - "\t`attendanceId`\tINTEGER NOT NULL,\n" + - "\t`attendanceLessonDate`\tTEXT NOT NULL,\n" + - "\t`attendanceStartTime`\tTEXT NOT NULL,\n" + - "\t`attendanceLessonTopic`\tTEXT,\n" + - "\t`attendanceSemester`\tINTEGER NOT NULL,\n" + - "\t`attendanceType`\tINTEGER NOT NULL,\n" + - "\t`teacherId`\tINTEGER NOT NULL,\n" + - "\t`subjectId`\tINTEGER NOT NULL,\n" + - "\tPRIMARY KEY(`profileId`,`attendanceId`,`attendanceLessonDate`,`attendanceStartTime`)\n" + - ");") - database.execSQL("DROP INDEX index_attendances_profileId") - database.execSQL("CREATE INDEX `index_attendances_profileId` ON `attendances` (\n" + - "\t`profileId`\n" + - ");") - database.execSQL("INSERT INTO attendances SELECT * FROM _attendances_old;") - database.execSQL("DROP TABLE _attendances_old;") - } - } - private val MIGRATION_23_24: Migration = object : Migration(23, 24) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE profiles ADD yearAverageMode INTEGER NOT NULL DEFAULT 0") - } - } - private val MIGRATION_24_25: Migration = object : Migration(24, 25) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE announcements (" + - "profileId INTEGER NOT NULL, " + - "announcementId INTEGER NOT NULL, " + - "announcementSubject TEXT, " + - "announcementText TEXT, " + - "announcementStartDate TEXT, " + - "announcementEndDate TEXT, " + - "teacherId INTEGER NOT NULL, " + - "PRIMARY KEY(profileId, announcementId));") - //database.execSQL("DROP INDEX index_announcements_profileId"); - database.execSQL("CREATE INDEX index_announcements_profileId ON announcements (" + - "profileId" + - ");") - } - } - private val MIGRATION_25_26: Migration = object : Migration(25, 26) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades ADD gradePointGrade INTEGER NOT NULL DEFAULT 0;") - } - } - private val MIGRATION_26_27: Migration = object : Migration(26, 27) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades ADD gradeValueMax REAL NOT NULL DEFAULT 0;") - } - } - private val MIGRATION_27_28: Migration = object : Migration(27, 28) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE gradeCategories (profileId INTEGER NOT NULL, categoryId INTEGER NOT NULL, weight REAL NOT NULL, color INTEGER NOT NULL, `text` TEXT, columns TEXT, valueFrom REAL NOT NULL, valueTo REAL NOT NULL, PRIMARY KEY(profileId, categoryId));") - database.execSQL("ALTER TABLE grades ADD gradeComment TEXT;") - } - } - private val MIGRATION_28_29: Migration = object : Migration(28, 29) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE feedbackMessages (messageId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, received INTEGER NOT NULL DEFAULT 0, sentTime INTEGER NOT NULL, `text` TEXT)") - } - } - private val MIGRATION_29_30: Migration = object : Migration(29, 30) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE feedbackMessages ADD fromUser TEXT DEFAULT NULL") - database.execSQL("ALTER TABLE feedbackMessages ADD fromUserName TEXT DEFAULT NULL") - } - } - private val MIGRATION_30_31: Migration = object : Migration(30, 31) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE messages (" + - "profileId INTEGER NOT NULL, " + - "messageId INTEGER NOT NULL, " + - "messageSubject TEXT, " + - "messageBody TEXT DEFAULT NULL, " + - "messageType INTEGER NOT NULL DEFAULT 0, " + - "senderId INTEGER NOT NULL DEFAULT -1, " + - "senderReplyId INTEGER NOT NULL DEFAULT -1, " + - "recipientIds TEXT DEFAULT NULL, " + - "recipientReplyIds TEXT DEFAULT NULL, " + - "readByRecipientDates TEXT DEFAULT NULL, " + - "overrideHasAttachments INTEGER NOT NULL DEFAULT 0, " + - "attachmentIds TEXT DEFAULT NULL, " + - "attachmentNames TEXT DEFAULT NULL, " + - "PRIMARY KEY(profileId, messageId));") - //database.execSQL("DROP INDEX index_announcements_profileId"); - database.execSQL("CREATE INDEX index_messages_profileId ON messages (" + - "profileId" + - ");") - } - } - private val MIGRATION_31_32: Migration = object : Migration(31, 32) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE messages ADD attachmentSizes TEXT DEFAULT NULL") - } - } - private val MIGRATION_32_33: Migration = object : Migration(32, 33) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("DROP TABLE messages") - database.execSQL("CREATE TABLE messages (" + - "profileId INTEGER NOT NULL, " + - "messageId INTEGER NOT NULL, " + - "messageSubject TEXT, " + - "messageBody TEXT DEFAULT NULL, " + - "messageType INTEGER NOT NULL DEFAULT 0, " + - "senderId INTEGER NOT NULL DEFAULT -1, " + - "senderReplyId INTEGER NOT NULL DEFAULT -1, " + - "overrideHasAttachments INTEGER NOT NULL DEFAULT 0, " + - "attachmentIds TEXT DEFAULT NULL, " + - "attachmentNames TEXT DEFAULT NULL, " + - "attachmentSizes TEXT DEFAULT NULL, " + - "PRIMARY KEY(profileId, messageId));") - //database.execSQL("DROP INDEX index_announcements_profileId"); - database.execSQL("CREATE INDEX index_messages_profileId ON messages (" + - "profileId" + - ");") - database.execSQL("CREATE TABLE messageRecipients (" + - "profileId INTEGER NOT NULL, " + - "messageRecipientId INTEGER NOT NULL DEFAULT -1, " + - "messageRecipientReplyId INTEGER NOT NULL DEFAULT -1, " + - "messageRecipientReadDate INTEGER NOT NULL DEFAULT -1, " + - "messageId INTEGER NOT NULL, " + - "PRIMARY KEY(profileId, messageRecipientId));") - } - } - private val MIGRATION_33_34: Migration = object : Migration(33, 34) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("DROP TABLE messageRecipients") - database.execSQL("CREATE TABLE messageRecipients (" + - "profileId INTEGER NOT NULL, " + - "messageRecipientId INTEGER NOT NULL DEFAULT -1, " + - "messageRecipientReplyId INTEGER NOT NULL DEFAULT -1, " + - "messageRecipientReadDate INTEGER NOT NULL DEFAULT -1, " + - "messageId INTEGER NOT NULL, " + - "PRIMARY KEY(profileId, messageRecipientId, messageId));") - } - } - private val MIGRATION_34_35: Migration = object : Migration(34, 35) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE teachers ADD teacherLoginId TEXT DEFAULT NULL;") - } - } - private val MIGRATION_35_36: Migration = object : Migration(35, 36) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET yearAverageMode = 4 WHERE yearAverageMode = 0") - } - } - private val MIGRATION_36_37: Migration = object : Migration(36, 37) { - override fun migrate(database: SupportSQLiteDatabase) {} - } - private val MIGRATION_37_38: Migration = object : Migration(37, 38) { - override fun migrate(database: SupportSQLiteDatabase) { - val today = Date.getToday() - val schoolYearStart = if (today.month < 9) today.year - 1 else today.year - database.execSQL("UPDATE profiles SET dateSemester1Start = '$schoolYearStart-09-01' WHERE dateSemester1Start IS NULL;") - database.execSQL("UPDATE profiles SET dateSemester2Start = '" + (schoolYearStart + 1) + "-02-01' WHERE dateSemester2Start IS NULL;") - database.execSQL("UPDATE profiles SET dateYearEnd = '" + (schoolYearStart + 1) + "-06-30' WHERE dateYearEnd IS NULL;") - } - } - private val MIGRATION_38_39: Migration = object : Migration(38, 39) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE debugLogs (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `text` TEXT);") - } - } - private val MIGRATION_39_40: Migration = object : Migration(39, 40) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE profiles ADD changedEndpoints TEXT DEFAULT NULL;") - } - } - private val MIGRATION_40_41: Migration = object : Migration(40, 41) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET empty = 1;") - } - } - private val MIGRATION_41_42: Migration = object : Migration(41, 42) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET empty = 1;") - } - } - private val MIGRATION_42_43: Migration = object : Migration(42, 43) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE profiles ADD lastFullSync INTEGER NOT NULL DEFAULT 0;") - } - } - private val MIGRATION_43_44: Migration = object : Migration(43, 44) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET empty = 1;") - database.execSQL("UPDATE profiles SET currentSemester = 1;") - } - } - private val MIGRATION_44_45: Migration = object : Migration(44, 45) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET empty = 1;") - } - } - private val MIGRATION_45_46: Migration = object : Migration(45, 46) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET lastFullSync = 0") - } - } - private val MIGRATION_46_47: Migration = object : Migration(46, 47) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE profiles SET lastFullSync = 0") - } - } - private val MIGRATION_47_48: Migration = object : Migration(47, 48) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE notices ADD points REAL NOT NULL DEFAULT 0") - database.execSQL("ALTER TABLE notices ADD category TEXT DEFAULT NULL") - } - } - private val MIGRATION_48_49: Migration = object : Migration(48, 49) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades ADD gradeParentId INTEGER NOT NULL DEFAULT -1") - } - } - private val MIGRATION_49_50: Migration = object : Migration(49, 50) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE grades ADD gradeIsImprovement INTEGER NOT NULL DEFAULT 0") - database.execSQL("DELETE FROM attendances WHERE attendances.profileId IN (SELECT profiles.profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 1)") - database.execSQL("UPDATE profiles SET empty = 1 WHERE profileId IN (SELECT profiles.profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 4)") - } - } - private val MIGRATION_50_51: Migration = object : Migration(50, 51) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE profiles ADD lastReceiversSync INTEGER NOT NULL DEFAULT 0") - database.execSQL("ALTER TABLE teachers ADD teacherType INTEGER NOT NULL DEFAULT 0") - } - } - private val MIGRATION_51_52: Migration = object : Migration(51, 52) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE teachers ADD teacherTypeDescription TEXT DEFAULT NULL") - } - } - private val MIGRATION_52_53: Migration = object : Migration(52, 53) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE IF NOT EXISTS teacherAbsence (" + - "profileId INTEGER NOT NULL," + - "teacherAbsenceId INTEGER NOT NULL," + - "teacherId INTEGER NOT NULL," + - "teacherAbsenceType INTEGER NOT NULL," + - "teacherAbsenceDateFrom TEXT NOT NULL," + - "teacherAbsenceDateTo TEXT NOT NULL," + - "PRIMARY KEY(profileId, teacherAbsenceId)" + - ")") - } - } - private val MIGRATION_53_54: Migration = object : Migration(53, 54) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE teacherAbsence ADD teacherAbsenceTimeFrom TEXT DEFAULT NULL") - database.execSQL("ALTER TABLE teacherAbsence ADD teacherAbsenceTimeTo TEXT DEFAULT NULL") - } - } - private val MIGRATION_54_55: Migration = object : Migration(54, 55) { - override fun migrate(database: SupportSQLiteDatabase) { - // 2019-10-21 for merge compatibility between 3.1.1 and api-v2 - // moved to Migration 55->56 - } - } - private val MIGRATION_55_56: Migration = object : Migration(55, 56) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE IF NOT EXISTS endpointTimers (" + - "profileId INTEGER NOT NULL," + - "endpointId INTEGER NOT NULL," + - "endpointLastSync INTEGER DEFAULT NULL," + - "endpointNextSync INTEGER NOT NULL DEFAULT 1," + - "endpointViewId INTEGER DEFAULT NULL," + - "PRIMARY KEY(profileId, endpointId)" + - ")") - database.execSQL("CREATE TABLE IF NOT EXISTS lessonRanges (" + - "profileId INTEGER NOT NULL," + - "lessonRangeNumber INTEGER NOT NULL," + - "lessonRangeStart TEXT NOT NULL," + - "lessonRangeEnd TEXT NOT NULL," + - "PRIMARY KEY(profileId, lessonRangeNumber)" + - ")") - } - } - private val MIGRATION_56_57: Migration = object : Migration(56, 57) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE gradeCategories ADD type INTEGER NOT NULL DEFAULT 0") - } - } - private val MIGRATION_57_58: Migration = object : Migration(57, 58) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE metadata RENAME TO _metadata_old;") - database.execSQL("DROP INDEX index_metadata_profileId_thingType_thingId;") - database.execSQL("UPDATE _metadata_old SET thingType = " + Metadata.TYPE_HOMEWORK + " WHERE thingType = " + Metadata.TYPE_EVENT + " AND thingId IN (SELECT eventId FROM events WHERE eventType = -1);") - database.execSQL("CREATE TABLE metadata (\n" + - "profileId INTEGER NOT NULL,\n" + - "metadataId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n" + - "thingType INTEGER NOT NULL,\n" + - "thingId INTEGER NOT NULL,\n" + - "seen INTEGER NOT NULL,\n" + - "notified INTEGER NOT NULL,\n" + - "addedDate INTEGER NOT NULL);") - database.execSQL("INSERT INTO metadata SELECT * FROM (SELECT * FROM _metadata_old ORDER BY addedDate DESC) GROUP BY thingId;") - database.execSQL("DROP TABLE _metadata_old;") - database.execSQL("CREATE UNIQUE INDEX index_metadata_profileId_thingType_thingId ON metadata (profileId, thingType, thingId);") - } - } - private val MIGRATION_58_59: Migration = object : Migration(58, 59) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("UPDATE metadata SET addedDate = addedDate*1000 WHERE addedDate < 10000000000;") - database.execSQL("INSERT INTO metadata (profileId, thingType, thingId, seen, notified, addedDate)\n" + - "SELECT profileId,\n" + - "10 AS thingType,\n" + - "luckyNumberDate*10000+substr(luckyNumberDate, 6)*100+substr(luckyNumberDate, 9) AS thingId,\n" + - "1 AS seen,\n" + - "1 AS notified,\n" + - "CAST(strftime('%s', luckyNumberDate) AS INT)*1000 AS addedDate\n" + - "FROM luckyNumbers;") - database.execSQL("ALTER TABLE luckyNumbers RENAME TO _old_luckyNumbers;") - database.execSQL("CREATE TABLE luckyNumbers (\n" + - "profileId INTEGER NOT NULL,\n" + - "luckyNumberDate INTEGER NOT NULL, \n" + - "luckyNumber INTEGER NOT NULL, \n" + - "PRIMARY KEY(profileId, luckyNumberDate))") - database.execSQL("INSERT INTO luckyNumbers (profileId, luckyNumberDate, luckyNumber)\n" + - "SELECT profileId,\n" + - "luckyNumberDate*10000+substr(luckyNumberDate, 6)*100+substr(luckyNumberDate, 9) AS luckyNumberDate,\n" + - "luckyNumber\n" + - "FROM _old_luckyNumbers;") - database.execSQL("DROP TABLE _old_luckyNumbers;") - } - } - private val MIGRATION_59_60: Migration = object : Migration(59, 60) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE notifications (\n" + - " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n" + - " title TEXT NOT NULL,\n" + - " `text` TEXT NOT NULL,\n" + - " `type` INTEGER NOT NULL,\n" + - " profileId INTEGER DEFAULT NULL,\n" + - " profileName TEXT DEFAULT NULL,\n" + - " posted INTEGER NOT NULL DEFAULT 0,\n" + - " viewId INTEGER DEFAULT NULL,\n" + - " extras TEXT DEFAULT NULL,\n" + - " addedDate INTEGER NOT NULL\n" + - ");") - database.execSQL("ALTER TABLE profiles ADD COLUMN disabledNotifications TEXT DEFAULT NULL") - } - } - private val MIGRATION_60_61: Migration = object : Migration(60, 61) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE IF NOT EXISTS teacherAbsenceTypes (" + - "profileId INTEGER NOT NULL," + - "teacherAbsenceTypeId INTEGER NOT NULL," + - "teacherAbsenceTypeName TEXT NOT NULL," + - "PRIMARY KEY(profileId, teacherAbsenceTypeId))") - database.execSQL("ALTER TABLE teacherAbsence ADD COLUMN teacherAbsenceName TEXT DEFAULT NULL") - } - } - private val MIGRATION_61_62: Migration = object : Migration(61, 62) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE IF NOT EXISTS classrooms (\n" + - " profileId INTEGER NOT NULL,\n" + - " id INTEGER NOT NULL,\n" + - " name TEXT NOT NULL,\n" + - " PRIMARY KEY(profileId, id)\n" + - ")") - database.execSQL("CREATE TABLE IF NOT EXISTS noticeTypes (\n" + - " profileId INTEGER NOT NULL,\n" + - " id INTEGER NOT NULL,\n" + - " name TEXT NOT NULL,\n" + - " PRIMARY KEY(profileId, id)\n" + - ")") - database.execSQL("CREATE TABLE IF NOT EXISTS attendanceTypes (\n" + - " profileId INTEGER NOT NULL,\n" + - " id INTEGER NOT NULL,\n" + - " name TEXT NOT NULL,\n" + - " type INTEGER NOT NULL,\n" + - " color INTEGER NOT NULL,\n" + - " PRIMARY KEY(profileId, id)\n" + - ")") - } - } - private val MIGRATION_62_63: Migration = object : Migration(62, 63) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE profiles ADD COLUMN accountNameLong TEXT DEFAULT NULL") - database.execSQL("ALTER TABLE profiles ADD COLUMN studentClassName TEXT DEFAULT NULL") - database.execSQL("ALTER TABLE profiles ADD COLUMN studentSchoolYear TEXT DEFAULT NULL") - } - } - private val MIGRATION_63_64: Migration = object : Migration(63, 64) { - override fun migrate(database: SupportSQLiteDatabase) { - //database.execSQL("ALTER TABLE lessons RENAME TO lessonsOld;"); - database.execSQL("CREATE TABLE timetable (" + - "profileId INTEGER NOT NULL," + - "id INTEGER NOT NULL," + - "type INTEGER NOT NULL," + - "date TEXT DEFAULT NULL," + - "lessonNumber INTEGER DEFAULT NULL," + - "startTime TEXT DEFAULT NULL," + - "endTime TEXT DEFAULT NULL," + - "subjectId INTEGER DEFAULT NULL," + - "teacherId INTEGER DEFAULT NULL," + - "teamId INTEGER DEFAULT NULL," + - "classroom TEXT DEFAULT NULL," + - "oldDate TEXT DEFAULT NULL," + - "oldLessonNumber INTEGER DEFAULT NULL," + - "oldStartTime TEXT DEFAULT NULL," + - "oldEndTime TEXT DEFAULT NULL," + - "oldSubjectId INTEGER DEFAULT NULL," + - "oldTeacherId INTEGER DEFAULT NULL," + - "oldTeamId INTEGER DEFAULT NULL," + - "oldClassroom TEXT DEFAULT NULL," + - "PRIMARY KEY(id));") - database.execSQL("CREATE INDEX index_lessons_profileId_type_date ON timetable (profileId, type, date);") - database.execSQL("CREATE INDEX index_lessons_profileId_type_oldDate ON timetable (profileId, type, oldDate);") - } - } - private val MIGRATION_64_65: Migration = object : Migration(64, 65) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE config (" + - "profileId INTEGER NOT NULL DEFAULT -1," + - "`key` TEXT NOT NULL," + - "value TEXT NOT NULL," + - "PRIMARY KEY(profileId, `key`));") - } - } - private val MIGRATION_65_66: Migration = object : Migration(65, 66) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("DROP TABLE config;") - database.execSQL("CREATE TABLE config (" + - "profileId INTEGER NOT NULL DEFAULT -1," + - "`key` TEXT NOT NULL," + - "value TEXT," + - "PRIMARY KEY(profileId, `key`));") - } - } - private val MIGRATION_66_67: Migration = object : Migration(66, 67) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("DELETE FROM grades WHERE (gradeId=-1 OR gradeId=-2) AND gradeType=20") - database.execSQL("DELETE FROM metadata WHERE (thingId=-1 OR thingId=-2) AND thingType=1") - database.execSQL("ALTER TABLE gradeCategories RENAME TO _gradeCategories") - database.execSQL("CREATE TABLE gradeCategories (" + - "profileId INTEGER NOT NULL," + - "categoryId INTEGER NOT NULL," + - "weight REAL NOT NULL," + - "color INTEGER NOT NULL," + - "`text` TEXT," + - "columns TEXT," + - "valueFrom REAL NOT NULL," + - "valueTo REAL NOT NULL," + - "type INTEGER NOT NULL," + - "PRIMARY KEY(profileId, categoryId, type))") - database.execSQL("INSERT INTO gradeCategories (profileId, categoryId, weight, color," + - "`text`, columns, valueFrom, valueTo, type) " + - "SELECT profileId, categoryId, weight, color, `text`, columns, valueFrom," + - "valueTo, type FROM _gradeCategories") - database.execSQL("DROP TABLE _gradeCategories") - } - } - private val MIGRATION_67_68: Migration = object : Migration(67, 68) { - override fun migrate(database: SupportSQLiteDatabase) { - /* Migration from crc16 to crc32 id */ - database.execSQL("DELETE FROM announcements") - database.execSQL("DELETE FROM metadata WHERE thingType=7") - } - } - private val MIGRATION_68_69: Migration = object : Migration(68, 69) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE loginStores ADD COLUMN loginStoreMode INTEGER NOT NULL DEFAULT 0") - } - } - private val MIGRATION_69_70: Migration = object : Migration(69, 70) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE announcements ADD COLUMN announcementIdString TEXT DEFAULT NULL") - database.execSQL("DELETE FROM announcements") - } - } - private val MIGRATION_70_71: Migration = object : Migration(70, 71) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("DELETE FROM messages WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0);") - database.execSQL("DELETE FROM messageRecipients WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0);") - database.execSQL("DELETE FROM teachers WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0);") - database.execSQL("DELETE FROM endpointTimers WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0);") - database.execSQL("DELETE FROM metadata WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0) AND thingType = 8;") - database.execSQL("UPDATE profiles SET empty = 1 WHERE archived = 0;") - database.execSQL("UPDATE profiles SET lastReceiversSync = 0 WHERE archived = 0;") - database.execSQL("INSERT INTO config (profileId, `key`, value) VALUES (-1, \"runSync\", \"true\");") - } - } - private val MIGRATION_71_72: Migration = object : Migration(71, 72) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE loginStores RENAME to _loginStores;") - database.execSQL("CREATE TABLE loginStores(" + - "loginStoreId INTEGER NOT NULL," + - "loginStoreType INTEGER NOT NULL," + - "loginStoreMode INTEGER NOT NULL," + - "loginStoreData TEXT NOT NULL," + - "PRIMARY KEY(loginStoreId));") - database.execSQL("INSERT INTO loginStores " + - "(loginStoreId, loginStoreType, loginStoreMode, loginStoreData) " + - "SELECT loginStoreId, loginStoreType, loginStoreMode, loginStoreData " + - "FROM _loginStores;") - database.execSQL("DROP TABLE _loginStores;") - database.execSQL("ALTER TABLE profiles RENAME TO _profiles_old;") - database.execSQL("CREATE TABLE profiles (\n" + - "profileId INTEGER NOT NULL, name TEXT NOT NULL, subname TEXT, image TEXT DEFAULT NULL, \n" + - "studentNameLong TEXT NOT NULL, studentNameShort TEXT NOT NULL, accountName TEXT, \n" + - "studentData TEXT NOT NULL, empty INTEGER NOT NULL DEFAULT 1, archived INTEGER NOT NULL DEFAULT 0, \n" + - "syncEnabled INTEGER NOT NULL DEFAULT 1, enableSharedEvents INTEGER NOT NULL DEFAULT 1, registration INTEGER NOT NULL DEFAULT 0, \n" + - "userCode TEXT NOT NULL DEFAULT \"\", studentNumber INTEGER NOT NULL DEFAULT -1, studentClassName TEXT DEFAULT NULL, \n" + - "studentSchoolYearStart INTEGER NOT NULL, dateSemester1Start TEXT NOT NULL, dateSemester2Start TEXT NOT NULL, \n" + - "dateYearEnd TEXT NOT NULL, disabledNotifications TEXT DEFAULT NULL, lastReceiversSync INTEGER NOT NULL DEFAULT 0, \n" + - "loginStoreId INTEGER NOT NULL, loginStoreType INTEGER NOT NULL, PRIMARY KEY(profileId));") - database.execSQL("INSERT INTO profiles (profileId, name, subname, image, studentNameLong, studentNameShort, accountName, \n" + - "userCode, studentData, empty, archived, syncEnabled, enableSharedEvents, registration, studentNumber, studentSchoolYearStart, \n" + - "dateSemester1Start, dateSemester2Start, dateYearEnd, lastReceiversSync, loginStoreId, loginStoreType \n" + - ") SELECT profileId, name, subname, image, studentNameLong, studentNameShort, accountNameLong, \"\" AS userCode, studentData, \n" + - "empty, archived, syncEnabled, enableSharedEvents, registration, studentNumber, SUBSTR(dateSemester1Start, 0, 5) AS studentSchoolYearStart, \n" + - "dateSemester1Start, dateSemester2Start, dateYearEnd, lastReceiversSync, _profiles_old.loginStoreId, loginStoreType FROM _profiles_old \n" + - "JOIN loginStores ON loginStores.loginStoreId = _profiles_old.loginStoreId \n" + - "WHERE profileId >= 0;") - database.execSQL("DROP TABLE _profiles_old;") - // MIGRACJA userCode - mobidziennik - database.execSQL("DROP TABLE IF EXISTS _userCodes;") - database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, serverName TEXT, username TEXT, studentId TEXT);") - database.execSQL("DELETE FROM _userCodes;") - database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 1;") - database.execSQL("UPDATE _userCodes SET serverName = SUBSTR(loginData, instr(loginData, '\"serverName\":\"')+14);") - database.execSQL("UPDATE _userCodes SET serverName = SUBSTR(serverName, 0, instr(serverName, '\",')+instr(serverName, '\"}')-(instr(serverName, '\"}')*min(instr(serverName, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET username = SUBSTR(loginData, instr(loginData, '\"username\":\"')+12);") - database.execSQL("UPDATE _userCodes SET username = SUBSTR(username, 0, instr(username, '\",')+instr(username, '\"}')-(instr(username, '\"}')*min(instr(username, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentData, instr(studentData, '\"studentId\":')+12);") - database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentId, 0, instr(studentId, ',')+instr(studentId, '}')-(instr(studentId, '}')*min(instr(studentId, ','), 1)));") - database.execSQL("UPDATE _userCodes SET userCode = serverName||\":\"||username||\":\"||studentId;") - database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") - // MIGRACJA userCode - librus - database.execSQL("DROP TABLE IF EXISTS _userCodes;") - database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, accountLogin TEXT);") - database.execSQL("DELETE FROM _userCodes;") - database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 2;") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(studentData, instr(studentData, '\"schoolName\":\"')+14);") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET accountLogin = SUBSTR(studentData, instr(studentData, '\"accountLogin\":\"')+16);") - database.execSQL("UPDATE _userCodes SET accountLogin = SUBSTR(accountLogin, 0, instr(accountLogin, '\",')+instr(accountLogin, '\"}')-(instr(accountLogin, '\"}')*min(instr(accountLogin, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||accountLogin;") - database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") - // MIGRACJA userCode - iuczniowie - database.execSQL("DROP TABLE IF EXISTS _userCodes;") - database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, username TEXT, registerId TEXT);") - database.execSQL("DELETE FROM _userCodes;") - database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 3;") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(loginData, instr(loginData, '\"schoolName\":\"')+14);") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET username = SUBSTR(loginData, instr(loginData, '\"username\":\"')+12);") - database.execSQL("UPDATE _userCodes SET username = SUBSTR(username, 0, instr(username, '\",')+instr(username, '\"}')-(instr(username, '\"}')*min(instr(username, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET registerId = SUBSTR(studentData, instr(studentData, '\"registerId\":')+13);") - database.execSQL("UPDATE _userCodes SET registerId = SUBSTR(registerId, 0, instr(registerId, ',')+instr(registerId, '}')-(instr(registerId, '}')*min(instr(registerId, ','), 1)));") - database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||username||\":\"||registerId;") - database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") - // MIGRACJA userCode - vulcan - database.execSQL("DROP TABLE IF EXISTS _userCodes;") - database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, studentId TEXT);") - database.execSQL("DELETE FROM _userCodes;") - database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 4;") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(studentData, instr(studentData, '\"schoolName\":\"')+14);") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentData, instr(studentData, '\"studentId\":')+12);") - database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentId, 0, instr(studentId, ',')+instr(studentId, '}')-(instr(studentId, '}')*min(instr(studentId, ','), 1)));") - database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||studentId;") - database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") - // MIGRACJA userCode - edudziennik - database.execSQL("DROP TABLE IF EXISTS _userCodes;") - database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, email TEXT, studentId TEXT);") - database.execSQL("DELETE FROM _userCodes;") - database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 5;") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(studentData, instr(studentData, '\"schoolName\":\"')+14);") - database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET email = SUBSTR(loginData, instr(loginData, '\"email\":\"')+9);") - database.execSQL("UPDATE _userCodes SET email = SUBSTR(email, 0, instr(email, '\",')+instr(email, '\"}')-(instr(email, '\"}')*min(instr(email, '\",'), 1)));") - database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentData, instr(studentData, '\"studentId\":\"')+13);") - database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentId, 0, instr(studentId, '\",')+instr(studentId, '\"}')-(instr(studentId, '\"}')*min(instr(studentId, '\",'), 1)));") - database.query("SELECT profileId, studentId FROM _userCodes;").use { cursor -> - while (cursor.moveToNext()) { - val profileId = cursor.getInt(0) - val crc = cursor.getString(1).crc32() - database.execSQL("UPDATE _userCodes SET studentId = $crc WHERE profileId = $profileId") - } - } - database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||email||\":\"||studentId;") - database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") - database.execSQL("DROP TABLE _userCodes;") - } - } - private val MIGRATION_72_73: Migration = object : Migration(72, 73) { - override fun migrate(database: SupportSQLiteDatabase) { // Mark as seen all lucky number metadata. - database.execSQL("UPDATE metadata SET seen=1 WHERE thingType=10") - database.execSQL("DROP TABLE lessons") - database.execSQL("DROP TABLE lessonChanges") - } - } - private val MIGRATION_73_74: Migration = object : Migration(73, 74) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE librusLessons (" + - "profileId INTEGER NOT NULL," + - "lessonId INTEGER NOT NULL," + - "teacherId INTEGER NOT NULL," + - "subjectId INTEGER NOT NULL," + - "teamId INTEGER," + - "PRIMARY KEY(profileId, lessonId));") - database.execSQL("CREATE INDEX index_librusLessons_profileId ON librusLessons (profileId);") - } - } - private val MIGRATION_74_75: Migration = object : Migration(74, 75) { - override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("ALTER TABLE timetable RENAME TO _timetable;") - database.execSQL("CREATE TABLE timetable (profileId INTEGER NOT NULL,id INTEGER NOT NULL,type INTEGER NOT NULL,date TEXT DEFAULT NULL,lessonNumber INTEGER DEFAULT NULL,startTime TEXT DEFAULT NULL,endTime TEXT DEFAULT NULL,subjectId INTEGER DEFAULT NULL,teacherId INTEGER DEFAULT NULL,teamId INTEGER DEFAULT NULL,classroom TEXT DEFAULT NULL,oldDate TEXT DEFAULT NULL,oldLessonNumber INTEGER DEFAULT NULL,oldStartTime TEXT DEFAULT NULL,oldEndTime TEXT DEFAULT NULL,oldSubjectId INTEGER DEFAULT NULL,oldTeacherId INTEGER DEFAULT NULL,oldTeamId INTEGER DEFAULT NULL,oldClassroom TEXT DEFAULT NULL,PRIMARY KEY(profileId, id));") - database.execSQL("INSERT INTO timetable (profileId, id, type, date, lessonNumber, startTime, endTime, subjectId, teacherId, teamId, classroom, oldDate, oldLessonNumber, oldStartTime, oldEndTime, oldSubjectId, oldTeacherId, oldTeamId, oldClassroom) SELECT profileId, id, type, date, lessonNumber, startTime, endTime, subjectId, teacherId, teamId, classroom, oldDate, oldLessonNumber, oldStartTime, oldEndTime, oldSubjectId, oldTeacherId, oldTeamId, oldClassroom FROM _timetable;") - database.execSQL("DROP TABLE _timetable;") - database.execSQL("CREATE INDEX index_lessons_profileId_type_date ON timetable (profileId, type, date);") - database.execSQL("CREATE INDEX index_lessons_profileId_type_oldDate ON timetable (profileId, type, oldDate);") - } - } - operator fun invoke(context: Context) = instance ?: synchronized(LOCK) { instance ?: buildDatabase(context).also { instance = it } } @@ -861,70 +95,70 @@ abstract class AppDb : RoomDatabase() { AppDb::class.java, "edziennik.db" ).addMigrations( - MIGRATION_11_12, - MIGRATION_12_13, - MIGRATION_13_14, - MIGRATION_14_15, - MIGRATION_15_16, - MIGRATION_16_17, - MIGRATION_17_18, - MIGRATION_18_19, - MIGRATION_19_20, - MIGRATION_20_21, - MIGRATION_21_22, - MIGRATION_22_23, - MIGRATION_23_24, - MIGRATION_24_25, - MIGRATION_25_26, - MIGRATION_26_27, - MIGRATION_27_28, - MIGRATION_28_29, - MIGRATION_29_30, - MIGRATION_30_31, - MIGRATION_31_32, - MIGRATION_32_33, - MIGRATION_33_34, - MIGRATION_34_35, - MIGRATION_35_36, - MIGRATION_36_37, - MIGRATION_37_38, - MIGRATION_38_39, - MIGRATION_39_40, - MIGRATION_40_41, - MIGRATION_41_42, - MIGRATION_42_43, - MIGRATION_43_44, - MIGRATION_44_45, - MIGRATION_45_46, - MIGRATION_46_47, - MIGRATION_47_48, - MIGRATION_48_49, - MIGRATION_49_50, - MIGRATION_50_51, - MIGRATION_51_52, - MIGRATION_52_53, - MIGRATION_53_54, - MIGRATION_54_55, - MIGRATION_55_56, - MIGRATION_56_57, - MIGRATION_57_58, - MIGRATION_58_59, - MIGRATION_59_60, - MIGRATION_60_61, - MIGRATION_61_62, - MIGRATION_62_63, - MIGRATION_63_64, - MIGRATION_64_65, - MIGRATION_65_66, - MIGRATION_66_67, - MIGRATION_67_68, - MIGRATION_68_69, - MIGRATION_69_70, - MIGRATION_70_71, - MIGRATION_71_72, - MIGRATION_72_73, - MIGRATION_73_74, - MIGRATION_74_75 + Migration12(), + Migration13(), + Migration14(), + Migration15(), + Migration16(), + Migration17(), + Migration18(), + Migration19(), + Migration20(), + Migration21(), + Migration22(), + Migration23(), + Migration24(), + Migration25(), + Migration26(), + Migration27(), + Migration28(), + Migration29(), + Migration30(), + Migration31(), + Migration32(), + Migration33(), + Migration34(), + Migration35(), + Migration36(), + Migration37(), + Migration38(), + Migration39(), + Migration40(), + Migration41(), + Migration42(), + Migration43(), + Migration44(), + Migration45(), + Migration46(), + Migration47(), + Migration48(), + Migration49(), + Migration50(), + Migration51(), + Migration52(), + Migration53(), + Migration54(), + Migration55(), + Migration56(), + Migration57(), + Migration58(), + Migration59(), + Migration60(), + Migration61(), + Migration62(), + Migration63(), + Migration64(), + Migration65(), + Migration66(), + Migration67(), + Migration68(), + Migration69(), + Migration70(), + Migration71(), + Migration72(), + Migration73(), + Migration74(), + Migration75() ).allowMainThreadQueries().build() } -} \ No newline at end of file +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration12.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration12.kt new file mode 100644 index 00000000..30e18c88 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration12.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration12 : Migration(11, 12) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("PRAGMA foreign_keys=off;") + database.execSQL("ALTER TABLE teams RENAME TO _teams_old;") + database.execSQL("CREATE TABLE teams (profileId INTEGER NOT NULL, teamId INTEGER NOT NULL, teamType INTEGER NOT NULL, teamName TEXT, teamTeacherId INTEGER NOT NULL, PRIMARY KEY(profileId, teamId));") + database.execSQL("INSERT INTO teams (profileId, teamId, teamType, teamName, teamTeacherId) SELECT profileId, teamId, teamType, teamName, teacherId FROM _teams_old;") + database.execSQL("DROP TABLE _teams_old;") + database.execSQL("PRAGMA foreign_keys=on;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration13.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration13.kt new file mode 100644 index 00000000..e863cb68 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration13.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration13 : Migration(12, 13) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE lessonChanges ADD lessonChangeWeekDay INTEGER NOT NULL DEFAULT -1;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration14.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration14.kt new file mode 100644 index 00000000..688da9a2 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration14.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration14 : Migration(13, 14) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("CREATE TABLE loginStores (loginStoreId INTEGER NOT NULL, loginStoreType INTEGER NOT NULL, loginStoreData TEXT, PRIMARY KEY(loginStoreId));") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration15.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration15.kt new file mode 100644 index 00000000..ec34612f --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration15.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration15 : Migration(14, 15) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades RENAME TO _grades_old;") + database.execSQL("CREATE TABLE `grades` (\n" + + "\t`profileId`\tINTEGER NOT NULL,\n" + + "\t`gradeId`\tINTEGER NOT NULL,\n" + + "\t`gradeDescription`\tTEXT,\n" + + "\t`gradeName`\tTEXT,\n" + + "\t`gradeValue`\tREAL NOT NULL,\n" + + "\t`gradeWeight`\tREAL NOT NULL,\n" + + "\t`gradeSemester`\tINTEGER NOT NULL,\n" + + "\t`gradeType`\tINTEGER NOT NULL,\n" + + "\t`teacherId`\tINTEGER NOT NULL,\n" + + "\t`categoryId`\tINTEGER NOT NULL,\n" + + "\t`subjectId`\tINTEGER NOT NULL,\n" + + "\tPRIMARY KEY(`profileId`,`gradeId`)\n" + + ");") + database.execSQL("INSERT INTO grades\n" + + " SELECT *\n" + + " FROM _grades_old;") + database.execSQL("DROP TABLE _grades_old;") + database.execSQL("CREATE INDEX index_grades_profileId ON grades (profileId);") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration16.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration16.kt new file mode 100644 index 00000000..579c2e55 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration16.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration16 : Migration(15, 16) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE profiles ( + profileId INTEGER NOT NULL, + name TEXT, + subname TEXT, + image TEXT, + syncEnabled INTEGER NOT NULL, + syncNotifications INTEGER NOT NULL, + enableSharedEvents INTEGER NOT NULL, + countInSeconds INTEGER NOT NULL, + loggedIn INTEGER NOT NULL, + empty INTEGER NOT NULL, + studentNameLong TEXT, + studentNameShort TEXT, + studentNumber INTEGER NOT NULL, + studentData TEXT, + registration INTEGER NOT NULL, + gradeColorMode INTEGER NOT NULL, + agendaViewType INTEGER NOT NULL, + currentSemester INTEGER NOT NULL, + attendancePercentage REAL NOT NULL, + dateSemester1Start TEXT, + dateSemester2Start TEXT, + dateYearEnd TEXT, + luckyNumberEnabled INTEGER NOT NULL, + luckyNumber INTEGER NOT NULL, + luckyNumberDate TEXT, + loginStoreId INTEGER NOT NULL, + PRIMARY KEY(profileId));""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration17.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration17.kt new file mode 100644 index 00000000..d033b408 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration17.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration17 : Migration(16, 17) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE profiles ADD archived INTEGER NOT NULL DEFAULT 0;") + database.execSQL("ALTER TABLE teams ADD teamCode TEXT;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration18.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration18.kt new file mode 100644 index 00000000..c213aa40 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration18.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration18 : Migration(17, 18) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE events ADD eventBlacklisted INTEGER NOT NULL DEFAULT 0;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration19.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration19.kt new file mode 100644 index 00000000..77c1b8d3 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration19.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration19 : Migration(18, 19) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades ADD gradeClassAverage REAL NOT NULL DEFAULT -1;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration20.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration20.kt new file mode 100644 index 00000000..bb5741a5 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration20.kt @@ -0,0 +1,18 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration20 : Migration(19, 20) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE luckyNumbers ( + profileId INTEGER NOT NULL, + luckyNumberDate TEXT NOT NULL, + luckyNumber INTEGER NOT NULL, + PRIMARY KEY(profileId, luckyNumberDate));""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration21.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration21.kt new file mode 100644 index 00000000..d69ea451 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration21.kt @@ -0,0 +1,16 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration21 : Migration(20, 21) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades ADD gradeCategory TEXT") + database.execSQL("ALTER TABLE grades ADD gradeColor INTEGER NOT NULL DEFAULT -1") + database.execSQL("DROP TABLE gradeCategories") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration22.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration22.kt new file mode 100644 index 00000000..fe90df4e --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration22.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration22 : Migration(21, 22) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE eventTypes ( + profileId INTEGER NOT NULL, + eventType INTEGER NOT NULL, + eventTypeName TEXT, + eventTypeColor INTEGER NOT NULL, + PRIMARY KEY(profileId, eventType));""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration23.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration23.kt new file mode 100644 index 00000000..ec290688 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration23.kt @@ -0,0 +1,53 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration23 : Migration(22, 23) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades RENAME TO _grades_old;") + database.execSQL("""CREATE TABLE `grades` ( + `profileId` INTEGER NOT NULL, + `gradeId` INTEGER NOT NULL, + `gradeCategory` TEXT, + `gradeColor` INTEGER NOT NULL DEFAULT -1, + `gradeDescription` TEXT, + `gradeName` TEXT, + `gradeValue` REAL NOT NULL, + `gradeWeight` REAL NOT NULL, + `gradeSemester` INTEGER NOT NULL, + `gradeClassAverage` REAL NOT NULL DEFAULT -1, + `gradeType` INTEGER NOT NULL, + `teacherId` INTEGER NOT NULL, + `subjectId` INTEGER NOT NULL, + PRIMARY KEY(`profileId`,`gradeId`))""") + + database.execSQL("DROP INDEX index_grades_profileId") + database.execSQL("CREATE INDEX `index_grades_profileId` ON `grades` (`profileId`)") + + database.execSQL("INSERT INTO grades (profileId, gradeId, gradeDescription, gradeName, gradeValue, gradeWeight, gradeSemester, gradeType, teacherId, subjectId, gradeClassAverage, gradeCategory, gradeColor) SELECT profileId, gradeId, gradeDescription, gradeName, gradeValue, gradeWeight, gradeSemester, gradeType, teacherId, subjectId, gradeClassAverage, gradeCategory, gradeColor FROM _grades_old;") + database.execSQL("DROP TABLE _grades_old;") + database.execSQL("ALTER TABLE attendances RENAME TO _attendances_old;") + + database.execSQL("""CREATE TABLE `attendances` ( + `profileId` INTEGER NOT NULL, + `attendanceId` INTEGER NOT NULL, + `attendanceLessonDate` TEXT NOT NULL, + `attendanceStartTime` TEXT NOT NULL, + `attendanceLessonTopic` TEXT, + `attendanceSemester` INTEGER NOT NULL, + `attendanceType` INTEGER NOT NULL, + `teacherId` INTEGER NOT NULL, + `subjectId` INTEGER NOT NULL, + PRIMARY KEY(`profileId`,`attendanceId`,`attendanceLessonDate`,`attendanceStartTime`))""") + + database.execSQL("DROP INDEX index_attendances_profileId") + database.execSQL("CREATE INDEX `index_attendances_profileId` ON `attendances` (`profileId`);") + database.execSQL("INSERT INTO attendances SELECT * FROM _attendances_old;") + database.execSQL("DROP TABLE _attendances_old;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration24.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration24.kt new file mode 100644 index 00000000..7235bf6e --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration24.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration24 : Migration(23, 24) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE profiles ADD yearAverageMode INTEGER NOT NULL DEFAULT 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration25.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration25.kt new file mode 100644 index 00000000..9ac59c2d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration25.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration25 : Migration(24, 25) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE announcements ( + profileId INTEGER NOT NULL, + announcementId INTEGER NOT NULL, + announcementSubject TEXT, + announcementText TEXT, + announcementStartDate TEXT, + announcementEndDate TEXT, + teacherId INTEGER NOT NULL, + PRIMARY KEY(profileId, announcementId))""") + database.execSQL("CREATE INDEX index_announcements_profileId ON announcements (profileId)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration26.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration26.kt new file mode 100644 index 00000000..1aa17f5f --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration26.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration26 : Migration(25, 26) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades ADD gradePointGrade INTEGER NOT NULL DEFAULT 0;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration27.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration27.kt new file mode 100644 index 00000000..e7ed81ff --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration27.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration27 : Migration(26, 27) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades ADD gradeValueMax REAL NOT NULL DEFAULT 0;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration28.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration28.kt new file mode 100644 index 00000000..5045a4fa --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration28.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration28 : Migration(27, 28) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("CREATE TABLE gradeCategories (profileId INTEGER NOT NULL, categoryId INTEGER NOT NULL, weight REAL NOT NULL, color INTEGER NOT NULL, `text` TEXT, columns TEXT, valueFrom REAL NOT NULL, valueTo REAL NOT NULL, PRIMARY KEY(profileId, categoryId));") + database.execSQL("ALTER TABLE grades ADD gradeComment TEXT;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration29.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration29.kt new file mode 100644 index 00000000..3b4baa4d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration29.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration29 : Migration(28, 29) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("CREATE TABLE feedbackMessages (messageId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, received INTEGER NOT NULL DEFAULT 0, sentTime INTEGER NOT NULL, `text` TEXT)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration30.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration30.kt new file mode 100644 index 00000000..fc6813e8 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration30.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration30 : Migration(29, 30) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE feedbackMessages ADD fromUser TEXT DEFAULT NULL") + database.execSQL("ALTER TABLE feedbackMessages ADD fromUserName TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration31.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration31.kt new file mode 100644 index 00000000..a29bff06 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration31.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration31 : Migration(30, 31) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE messages ( + profileId INTEGER NOT NULL, + messageId INTEGER NOT NULL, + messageSubject TEXT, + messageBody TEXT DEFAULT NULL, + messageType INTEGER NOT NULL DEFAULT 0, + senderId INTEGER NOT NULL DEFAULT -1, + senderReplyId INTEGER NOT NULL DEFAULT -1, + recipientIds TEXT DEFAULT NULL, + recipientReplyIds TEXT DEFAULT NULL, + readByRecipientDates TEXT DEFAULT NULL, + overrideHasAttachments INTEGER NOT NULL DEFAULT 0, + attachmentIds TEXT DEFAULT NULL, + attachmentNames TEXT DEFAULT NULL, + PRIMARY KEY(profileId, messageId))""") + database.execSQL("CREATE INDEX index_messages_profileId ON messages (profileId)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration32.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration32.kt new file mode 100644 index 00000000..800e863f --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration32.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration32 : Migration(31, 32) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE messages ADD attachmentSizes TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration33.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration33.kt new file mode 100644 index 00000000..530620a4 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration33.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration33 : Migration(32, 33) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE messages") + database.execSQL("""CREATE TABLE messages ( + profileId INTEGER NOT NULL, + messageId INTEGER NOT NULL, + messageSubject TEXT, + messageBody TEXT DEFAULT NULL, + messageType INTEGER NOT NULL DEFAULT 0, + senderId INTEGER NOT NULL DEFAULT -1, + senderReplyId INTEGER NOT NULL DEFAULT -1, + overrideHasAttachments INTEGER NOT NULL DEFAULT 0, + attachmentIds TEXT DEFAULT NULL, + attachmentNames TEXT DEFAULT NULL, + attachmentSizes TEXT DEFAULT NULL, + PRIMARY KEY(profileId, messageId))""") + database.execSQL("CREATE INDEX index_messages_profileId ON messages (profileId)") + + database.execSQL("""CREATE TABLE messageRecipients ( + profileId INTEGER NOT NULL, + messageRecipientId INTEGER NOT NULL DEFAULT -1, + messageRecipientReplyId INTEGER NOT NULL DEFAULT -1, + messageRecipientReadDate INTEGER NOT NULL DEFAULT -1, + messageId INTEGER NOT NULL, + PRIMARY KEY(profileId, messageRecipientId))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration34.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration34.kt new file mode 100644 index 00000000..6a081edc --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration34.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration34 : Migration(33, 34) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE messageRecipients") + database.execSQL("""CREATE TABLE messageRecipients ( + profileId INTEGER NOT NULL, + messageRecipientId INTEGER NOT NULL DEFAULT -1, + messageRecipientReplyId INTEGER NOT NULL DEFAULT -1, + messageRecipientReadDate INTEGER NOT NULL DEFAULT -1, + messageId INTEGER NOT NULL, + PRIMARY KEY(profileId, messageRecipientId, messageId))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration35.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration35.kt new file mode 100644 index 00000000..e588ecad --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration35.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration35 : Migration(34, 35) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE teachers ADD teacherLoginId TEXT DEFAULT NULL;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration36.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration36.kt new file mode 100644 index 00000000..c37ca84a --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration36.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration36 : Migration(35, 36) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET yearAverageMode = 4 WHERE yearAverageMode = 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration37.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration37.kt new file mode 100644 index 00000000..00035a96 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration37.kt @@ -0,0 +1,12 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration37 : Migration(36, 37) { + override fun migrate(database: SupportSQLiteDatabase) {} +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration38.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration38.kt new file mode 100644 index 00000000..86b00f44 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration38.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase +import pl.szczodrzynski.edziennik.utils.models.Date + +class Migration38 : Migration(37, 38) { + override fun migrate(database: SupportSQLiteDatabase) { + val today = Date.getToday() + val schoolYearStart = if (today.month < 9) today.year - 1 else today.year + database.execSQL("UPDATE profiles SET dateSemester1Start = '$schoolYearStart-09-01' WHERE dateSemester1Start IS NULL") + database.execSQL("UPDATE profiles SET dateSemester2Start = '${schoolYearStart + 1}-02-01' WHERE dateSemester2Start IS NULL") + database.execSQL("UPDATE profiles SET dateYearEnd = '${schoolYearStart + 1}-06-30' WHERE dateYearEnd IS NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration39.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration39.kt new file mode 100644 index 00000000..d13805f2 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration39.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration39 : Migration(38, 39) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("CREATE TABLE debugLogs (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `text` TEXT)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration40.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration40.kt new file mode 100644 index 00000000..facbfc7c --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration40.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration40 : Migration(39, 40) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE profiles ADD changedEndpoints TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration41.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration41.kt new file mode 100644 index 00000000..7b6236ab --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration41.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration41 : Migration(40, 41) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET empty = 1") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration42.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration42.kt new file mode 100644 index 00000000..e4b8fcfa --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration42.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration42 : Migration(41, 42) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET empty = 1") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration43.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration43.kt new file mode 100644 index 00000000..524e7b3e --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration43.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration43 : Migration(42, 43) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE profiles ADD lastFullSync INTEGER NOT NULL DEFAULT 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration44.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration44.kt new file mode 100644 index 00000000..a800473c --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration44.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration44 : Migration(43, 44) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET empty = 1") + database.execSQL("UPDATE profiles SET currentSemester = 1") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration45.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration45.kt new file mode 100644 index 00000000..25a3d773 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration45.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration45 : Migration(44, 45) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET empty = 1") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration46.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration46.kt new file mode 100644 index 00000000..0025f991 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration46.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration46 : Migration(45, 46) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET lastFullSync = 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration47.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration47.kt new file mode 100644 index 00000000..a7d8f90c --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration47.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration47 : Migration(46, 47) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE profiles SET lastFullSync = 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration48.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration48.kt new file mode 100644 index 00000000..516115e8 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration48.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration48 : Migration(47, 48) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE notices ADD points REAL NOT NULL DEFAULT 0") + database.execSQL("ALTER TABLE notices ADD category TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration49.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration49.kt new file mode 100644 index 00000000..fa98dc23 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration49.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration49 : Migration(48, 49) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades ADD gradeParentId INTEGER NOT NULL DEFAULT -1") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration50.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration50.kt new file mode 100644 index 00000000..361f6c8d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration50.kt @@ -0,0 +1,16 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration50 : Migration(49, 50) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE grades ADD gradeIsImprovement INTEGER NOT NULL DEFAULT 0") + database.execSQL("DELETE FROM attendances WHERE attendances.profileId IN (SELECT profiles.profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 1)") + database.execSQL("UPDATE profiles SET empty = 1 WHERE profileId IN (SELECT profiles.profileId FROM profiles JOIN loginStores USING(loginStoreId) WHERE loginStores.loginStoreType = 4)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration51.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration51.kt new file mode 100644 index 00000000..05ef3ff6 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration51.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration51 : Migration(50, 51) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE profiles ADD lastReceiversSync INTEGER NOT NULL DEFAULT 0") + database.execSQL("ALTER TABLE teachers ADD teacherType INTEGER NOT NULL DEFAULT 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration52.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration52.kt new file mode 100644 index 00000000..aa1a2638 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration52.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration52 : Migration(51, 52) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE teachers ADD teacherTypeDescription TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration53.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration53.kt new file mode 100644 index 00000000..04a2aa70 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration53.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration53 : Migration(52, 53) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE IF NOT EXISTS teacherAbsence ( + profileId INTEGER NOT NULL, + teacherAbsenceId INTEGER NOT NULL, + teacherId INTEGER NOT NULL, + teacherAbsenceType INTEGER NOT NULL, + teacherAbsenceDateFrom TEXT NOT NULL, + teacherAbsenceDateTo TEXT NOT NULL, + PRIMARY KEY(profileId, teacherAbsenceId))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration54.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration54.kt new file mode 100644 index 00000000..26285a7a --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration54.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration54 : Migration(53, 54) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE teacherAbsence ADD teacherAbsenceTimeFrom TEXT DEFAULT NULL") + database.execSQL("ALTER TABLE teacherAbsence ADD teacherAbsenceTimeTo TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration55.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration55.kt new file mode 100644 index 00000000..bbeb16a2 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration55.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration55 : Migration(54, 55) { + override fun migrate(database: SupportSQLiteDatabase) { + // 2019-10-21 for merge compatibility between 3.1.1 and api-v2 + // moved to Migration 55->56 + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration56.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration56.kt new file mode 100644 index 00000000..4d04633e --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration56.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration56 : Migration(55, 56) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE IF NOT EXISTS endpointTimers ( + profileId INTEGER NOT NULL, + endpointId INTEGER NOT NULL, + endpointLastSync INTEGER DEFAULT NULL, + endpointNextSync INTEGER NOT NULL DEFAULT 1, + endpointViewId INTEGER DEFAULT NULL, + PRIMARY KEY(profileId, endpointId))""") + + database.execSQL("""CREATE TABLE IF NOT EXISTS lessonRanges ( + profileId INTEGER NOT NULL, + lessonRangeNumber INTEGER NOT NULL, + lessonRangeStart TEXT NOT NULL, + LessonRangeEnd TEXT NOT NULL, + PRIMARY KEY(profileId, lessonRangeNumber))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration57.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration57.kt new file mode 100644 index 00000000..d46cb60d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration57.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration57 : Migration(56, 57) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE gradeCategories ADD type INTEGER NOT NULL DEFAULT 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration58.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration58.kt new file mode 100644 index 00000000..d0ebf548 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration58.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase +import pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_EVENT +import pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_HOMEWORK + +class Migration58 : Migration(57, 58) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE metadata RENAME TO _metadata_old;") + database.execSQL("DROP INDEX index_metadata_profileId_thingType_thingId;") + database.execSQL("UPDATE _metadata_old SET thingType = $TYPE_HOMEWORK WHERE thingType = $TYPE_EVENT AND thingId IN (SELECT eventId FROM events WHERE eventType = -1)") + database.execSQL("""CREATE TABLE metadata ( + profileId INTEGER NOT NULL, + metadataId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + thingType INTEGER NOT NULL, + thingId INTEGER NOT NULL, + seen INTEGER NOT NULL, + notified INTEGER NOT NULL, + addedDate INTEGER NOT NULL)""") + database.execSQL("INSERT INTO metadata SELECT * FROM (SELECT * FROM _metadata_old ORDER BY addedDate DESC) GROUP BY thingId;") + database.execSQL("DROP TABLE _metadata_old;") + database.execSQL("CREATE UNIQUE INDEX index_metadata_profileId_thingType_thingId ON metadata (profileId, thingType, thingId);") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration59.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration59.kt new file mode 100644 index 00000000..d7ead712 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration59.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration59 : Migration(58, 59) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("UPDATE metadata SET addedDate = addedDate*1000 WHERE addedDate < 10000000000;") + database.execSQL("""INSERT INTO metadata (profileId, thingType, thingId, seen, notified, addedDate) + SELECT profileId, + 10 AS thingType, + luckyNumberDate*10000+substr(luckyNumberDate, 6)*100+substr(luckyNumberDate, 9) AS thingId, + 1 AS seen, + 1 AS notified, + CAST(strftime('%s', luckyNumberDate) AS INT)*1000 AS addedDate + FROM luckyNumbers""") + + database.execSQL("ALTER TABLE luckyNumbers RENAME TO _old_luckyNumbers;") + database.execSQL("""CREATE TABLE luckyNumbers ( + profileId INTEGER NOT NULL, + luckyNumberDate INTEGER NOT NULL, + luckyNumber INTEGER NOT NULL, + PRIMARY KEY(profileId, luckyNumberDate))""") + + database.execSQL("""INSERT INTO luckyNumbers (profileId, luckyNumberDate, luckyNumber) + SELECT profileId, + luckyNumberDate * 10000 + substr(luckyNumberDate, 6) * 100 + substr(luckyNumberDate, 9) AS luckyNumberDate, + luckyNumber FROM _old_luckyNumbers;""") + database.execSQL("DROP TABLE _old_luckyNumbers;") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration60.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration60.kt new file mode 100644 index 00000000..a518212e --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration60.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration60 : Migration(59, 60) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE notifications ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + title TEXT NOT NULL, + `text` TEXT NOT NULL, + `type` INTEGER NOT NULL, + profileId INTEGER DEFAULT NULL, + profileName TEXT DEFAULT NULL, + posted INTEGER NOT NULL DEFAULT 0, + viewId INTEGER DEFAULT NULL, + extras TEXT DEFAULT NULL, + addedDate INTEGER NOT NULL)""") + database.execSQL("ALTER TABLE profiles ADD COLUMN disabledNotifications TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration61.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration61.kt new file mode 100644 index 00000000..334ecb65 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration61.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration61 : Migration(60, 61) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE IF NOT EXISTS teacherAbsenceTypes ( + profileId INTEGER NOT NULL, + teacherAbsenceTypeId INTEGER NOT NULL, + teacherAbsenceTypeName TEXT NOT NULL, + PRIMARY KEY(profileId, teacherAbsenceTypeId))""") + database.execSQL("ALTER TABLE teacherAbsence ADD COLUMN teacherAbsenceName TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration62.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration62.kt new file mode 100644 index 00000000..86f70b04 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration62.kt @@ -0,0 +1,32 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration62 : Migration(61, 62) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE IF NOT EXISTS classrooms ( + profileId INTEGER NOT NULL, + id INTEGER NOT NULL, + name TEXT NOT NULL, + PRIMARY KEY(profileId, id))""") + + database.execSQL("""CREATE TABLE IF NOT EXISTS noticeTypes ( + profileId INTEGER NOT NULL, + id INTEGER NOT NULL, + name TEXT NOT NULL, + PRIMARY KEY(profileId, id))""") + + database.execSQL("""CREATE TABLE IF NOT EXISTS attendanceTypes ( + profileId INTEGER NOT NULL, + id INTEGER NOT NULL, + name TEXT NOT NULL, + type INTEGER NOT NULL, + color INTEGER NOT NULL, + PRIMARY KEY(profileId, id))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration63.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration63.kt new file mode 100644 index 00000000..659af38d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration63.kt @@ -0,0 +1,16 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration63 : Migration(62, 63) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE profiles ADD COLUMN accountNameLong TEXT DEFAULT NULL") + database.execSQL("ALTER TABLE profiles ADD COLUMN studentClassName TEXT DEFAULT NULL") + database.execSQL("ALTER TABLE profiles ADD COLUMN studentSchoolYear TEXT DEFAULT NULL") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration64.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration64.kt new file mode 100644 index 00000000..fba1d2c7 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration64.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration64 : Migration(63, 64) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE timetable ( + profileId INTEGER NOT NULL, + id INTEGER NOT NULL, + type INTEGER NOT NULL, + date TEXT DEFAULT NULL, + lessonNumber INTEGER DEFAULT NULL, + startTime TEXT DEFAULT NULL, + endTime TEXT DEFAULT NULL, + subjectId INTEGER DEFAULT NULL, + teacherId INTEGER DEFAULT NULL, + teamId INTEGER DEFAULT NULL, + classroom TEXT DEFAULT NULL, + oldDate TEXT DEFAULT NULL, + oldLessonNumber INTEGER DEFAULT NULL, + oldStartTime TEXT DEFAULT NULL, + oldEndTime TEXT DEFAULT NULL, + oldSubjectId INTEGER DEFAULT NULL, + oldTeacherId INTEGER DEFAULT NULL, + oldTeamId INTEGER DEFAULT NULL, + oldClassroom TEXT DEFAULT NULL, + PRIMARY KEY(id))""") + + database.execSQL("CREATE INDEX index_lessons_profileId_type_date ON timetable (profileId, type, date)") + database.execSQL("CREATE INDEX index_lessons_profileId_type_oldDate ON timetable (profileId, type, oldDate)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration65.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration65.kt new file mode 100644 index 00000000..8c432f82 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration65.kt @@ -0,0 +1,18 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration65 : Migration(64, 65) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE config ( + profileId INTEGER NOT NULL DEFAULT -1, + `key` TEXT NOT NULL, + value TEXT NOT NULL, + PRIMARY KEY(profileId, `key`))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration66.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration66.kt new file mode 100644 index 00000000..31ab6bdb --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration66.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration66 : Migration(65, 66) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE config;") + database.execSQL("""CREATE TABLE config ( + profileId INTEGER NOT NULL DEFAULT -1, + `key` TEXT NOT NULL, + value TEXT, + PRIMARY KEY(profileId, `key`))""") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration67.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration67.kt new file mode 100644 index 00000000..e64d63bf --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration67.kt @@ -0,0 +1,34 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration67 : Migration(66, 67) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DELETE FROM grades WHERE (gradeId=-1 OR gradeId=-2) AND gradeType=20") + database.execSQL("DELETE FROM metadata WHERE (thingId=-1 OR thingId=-2) AND thingType=1") + database.execSQL("ALTER TABLE gradeCategories RENAME TO _gradeCategories") + + database.execSQL("""CREATE TABLE gradeCategories ( + profileId INTEGER NOT NULL, + categoryId INTEGER NOT NULL, + weight REAL NOT NULL, + color INTEGER NOT NULL, + `text` TEXT, + columns TEXT, + valueFrom REAL NOT NULL, + valueTo REAL NOT NULL, + type INTEGER NOT NULL, + PRIMARY KEY(profileId, categoryId, type))""") + + database.execSQL("""INSERT INTO gradeCategories (profileId, categoryId, weight, color, + `text`, columns, valueFrom, valueTo, type) + SELECT profileId, categoryId, weight, color, `text`, columns, valueFrom, + valueTo, type FROM _gradeCategories""") + database.execSQL("DROP TABLE _gradeCategories") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration68.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration68.kt new file mode 100644 index 00000000..f7a079d0 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration68.kt @@ -0,0 +1,17 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase +import pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_ANNOUNCEMENT + +class Migration68 : Migration(67, 68) { + override fun migrate(database: SupportSQLiteDatabase) { + /* Migration from crc16 to crc32 id */ + database.execSQL("DELETE FROM announcements") + database.execSQL("DELETE FROM metadata WHERE thingType=$TYPE_ANNOUNCEMENT") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration69.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration69.kt new file mode 100644 index 00000000..1fd6760d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration69.kt @@ -0,0 +1,14 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration69 : Migration(68, 69) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE loginStores ADD COLUMN loginStoreMode INTEGER NOT NULL DEFAULT 0") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration70.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration70.kt new file mode 100644 index 00000000..1696301d --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration70.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration70 : Migration(69, 70) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE announcements ADD COLUMN announcementIdString TEXT DEFAULT NULL") + database.execSQL("DELETE FROM announcements") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration71.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration71.kt new file mode 100644 index 00000000..dabb2303 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration71.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase +import pl.szczodrzynski.edziennik.data.db.entity.Metadata.TYPE_MESSAGE + +class Migration71 : Migration(70, 71) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DELETE FROM messages WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0)") + database.execSQL("DELETE FROM messageRecipients WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0)") + database.execSQL("DELETE FROM teachers WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0)") + database.execSQL("DELETE FROM endpointTimers WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0)") + database.execSQL("DELETE FROM metadata WHERE profileId IN (SELECT profileId FROM profiles WHERE archived = 0) AND thingType = $TYPE_MESSAGE") + database.execSQL("UPDATE profiles SET empty = 1 WHERE archived = 0") + database.execSQL("UPDATE profiles SET lastReceiversSync = 0 WHERE archived = 0") + database.execSQL("INSERT INTO config (profileId, `key`, value) VALUES (-1, 'runSync', 'true')") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration72.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration72.kt new file mode 100644 index 00000000..88567b47 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration72.kt @@ -0,0 +1,138 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase +import pl.szczodrzynski.edziennik.crc32 + +class Migration72 : Migration(71, 72) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE loginStores RENAME to _loginStores;") + database.execSQL("""CREATE TABLE loginStores( + loginStoreId INTEGER NOT NULL, + loginStoreType INTEGER NOT NULL, + loginStoreMode INTEGER NOT NULL, + loginStoreData TEXT NOT NULL, + PRIMARY KEY(loginStoreId))""") + + database.execSQL("""INSERT INTO loginStores + (loginStoreId, loginStoreType, loginStoreMode, loginStoreData) + SELECT loginStoreId, loginStoreType, loginStoreMode, loginStoreData + FROM _loginStores""") + + database.execSQL("DROP TABLE _loginStores;") + database.execSQL("ALTER TABLE profiles RENAME TO _profiles_old;") + + database.execSQL("""CREATE TABLE profiles ( + profileId INTEGER NOT NULL, name TEXT NOT NULL, subname TEXT, image TEXT DEFAULT NULL, + studentNameLong TEXT NOT NULL, studentNameShort TEXT NOT NULL, accountName TEXT, + studentData TEXT NOT NULL, empty INTEGER NOT NULL DEFAULT 1, archived INTEGER NOT NULL DEFAULT 0, + syncEnabled INTEGER NOT NULL DEFAULT 1, enableSharedEvents INTEGER NOT NULL DEFAULT 1, registration INTEGER NOT NULL DEFAULT 0, + userCode TEXT NOT NULL DEFAULT '', studentNumber INTEGER NOT NULL DEFAULT -1, studentClassName TEXT DEFAULT NULL, + studentSchoolYearStart INTEGER NOT NULL, dateSemester1Start TEXT NOT NULL, dateSemester2Start TEXT NOT NULL, + dateYearEnd TEXT NOT NULL, disabledNotifications TEXT DEFAULT NULL, lastReceiversSync INTEGER NOT NULL DEFAULT 0, + loginStoreId INTEGER NOT NULL, loginStoreType INTEGER NOT NULL, PRIMARY KEY(profileId))""") + + database.execSQL("""INSERT INTO profiles (profileId, name, subname, image, studentNameLong, studentNameShort, accountName, + userCode, studentData, empty, archived, syncEnabled, enableSharedEvents, registration, studentNumber, studentSchoolYearStart, + dateSemester1Start, dateSemester2Start, dateYearEnd, lastReceiversSync, loginStoreId, loginStoreType) + SELECT profileId, name, subname, image, studentNameLong, studentNameShort, accountNameLong, '' AS userCode, studentData, + empty, archived, syncEnabled, enableSharedEvents, registration, studentNumber, SUBSTR(dateSemester1Start, 0, 5) AS studentSchoolYearStart, + dateSemester1Start, dateSemester2Start, dateYearEnd, lastReceiversSync, _profiles_old.loginStoreId, loginStoreType FROM _profiles_old + JOIN loginStores ON loginStores.loginStoreId = _profiles_old.loginStoreId WHERE profileId >= 0""") + + database.execSQL("DROP TABLE _profiles_old;") + + migrateUserCodes(database) + } + + private fun migrateMobidziennik(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS _userCodes;") + database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, serverName TEXT, username TEXT, studentId TEXT);") + database.execSQL("DELETE FROM _userCodes;") + database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 1;") + database.execSQL("UPDATE _userCodes SET serverName = SUBSTR(loginData, instr(loginData, '\"serverName\":\"')+14);") + database.execSQL("UPDATE _userCodes SET serverName = SUBSTR(serverName, 0, instr(serverName, '\",')+instr(serverName, '\"}')-(instr(serverName, '\"}')*min(instr(serverName, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET username = SUBSTR(loginData, instr(loginData, '\"username\":\"')+12);") + database.execSQL("UPDATE _userCodes SET username = SUBSTR(username, 0, instr(username, '\",')+instr(username, '\"}')-(instr(username, '\"}')*min(instr(username, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentData, instr(studentData, '\"studentId\":')+12);") + database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentId, 0, instr(studentId, ',')+instr(studentId, '}')-(instr(studentId, '}')*min(instr(studentId, ','), 1)));") + database.execSQL("UPDATE _userCodes SET userCode = serverName||\":\"||username||\":\"||studentId;") + database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") + } + + private fun migrateLibrus(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS _userCodes;") + database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, accountLogin TEXT);") + database.execSQL("DELETE FROM _userCodes;") + database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 2;") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(studentData, instr(studentData, '\"schoolName\":\"')+14);") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET accountLogin = SUBSTR(studentData, instr(studentData, '\"accountLogin\":\"')+16);") + database.execSQL("UPDATE _userCodes SET accountLogin = SUBSTR(accountLogin, 0, instr(accountLogin, '\",')+instr(accountLogin, '\"}')-(instr(accountLogin, '\"}')*min(instr(accountLogin, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||accountLogin;") + database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") + } + + private fun migrateIUczniowie(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS _userCodes;") + database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, username TEXT, registerId TEXT);") + database.execSQL("DELETE FROM _userCodes;") + database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 3;") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(loginData, instr(loginData, '\"schoolName\":\"')+14);") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET username = SUBSTR(loginData, instr(loginData, '\"username\":\"')+12);") + database.execSQL("UPDATE _userCodes SET username = SUBSTR(username, 0, instr(username, '\",')+instr(username, '\"}')-(instr(username, '\"}')*min(instr(username, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET registerId = SUBSTR(studentData, instr(studentData, '\"registerId\":')+13);") + database.execSQL("UPDATE _userCodes SET registerId = SUBSTR(registerId, 0, instr(registerId, ',')+instr(registerId, '}')-(instr(registerId, '}')*min(instr(registerId, ','), 1)));") + database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||username||\":\"||registerId;") + database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") + } + + private fun migrateVulcan(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS _userCodes;") + database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, studentId TEXT);") + database.execSQL("DELETE FROM _userCodes;") + database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 4;") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(studentData, instr(studentData, '\"schoolName\":\"')+14);") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentData, instr(studentData, '\"studentId\":')+12);") + database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentId, 0, instr(studentId, ',')+instr(studentId, '}')-(instr(studentId, '}')*min(instr(studentId, ','), 1)));") + database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||studentId;") + database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") + } + + private fun migrateEdudziennik(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE IF EXISTS _userCodes;") + database.execSQL("CREATE TABLE _userCodes (profileId INTEGER, loginData TEXT, studentData TEXT, userCode TEXT, schoolName TEXT, email TEXT, studentId TEXT);") + database.execSQL("DELETE FROM _userCodes;") + database.execSQL("INSERT INTO _userCodes SELECT profileId, loginStores.loginStoreData, studentData, \"\", \"\", \"\", \"\" FROM profiles JOIN loginStores ON loginStores.loginStoreId = profiles.loginStoreId WHERE profiles.loginStoreType = 5;") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(studentData, instr(studentData, '\"schoolName\":\"')+14);") + database.execSQL("UPDATE _userCodes SET schoolName = SUBSTR(schoolName, 0, instr(schoolName, '\",')+instr(schoolName, '\"}')-(instr(schoolName, '\"}')*min(instr(schoolName, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET email = SUBSTR(loginData, instr(loginData, '\"email\":\"')+9);") + database.execSQL("UPDATE _userCodes SET email = SUBSTR(email, 0, instr(email, '\",')+instr(email, '\"}')-(instr(email, '\"}')*min(instr(email, '\",'), 1)));") + database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentData, instr(studentData, '\"studentId\":\"')+13);") + database.execSQL("UPDATE _userCodes SET studentId = SUBSTR(studentId, 0, instr(studentId, '\",')+instr(studentId, '\"}')-(instr(studentId, '\"}')*min(instr(studentId, '\",'), 1)));") + database.query("SELECT profileId, studentId FROM _userCodes;").use { cursor -> + while (cursor.moveToNext()) { + val profileId = cursor.getInt(0) + val crc = cursor.getString(1).crc32() + database.execSQL("UPDATE _userCodes SET studentId = $crc WHERE profileId = $profileId") + } + } + database.execSQL("UPDATE _userCodes SET userCode = schoolName||\":\"||email||\":\"||studentId;") + database.execSQL("UPDATE profiles SET userCode = (SELECT userCode FROM _userCodes WHERE profileId = profiles.profileId) WHERE profileId IN (SELECT profileId FROM _userCodes);") + database.execSQL("DROP TABLE _userCodes;") + } + + private fun migrateUserCodes(database: SupportSQLiteDatabase) { + migrateMobidziennik(database) + migrateLibrus(database) + migrateVulcan(database) + migrateIUczniowie(database) + migrateEdudziennik(database) + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration73.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration73.kt new file mode 100644 index 00000000..cb8e29e8 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration73.kt @@ -0,0 +1,16 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration73 : Migration(72, 73) { + override fun migrate(database: SupportSQLiteDatabase) { // Mark as seen all lucky number metadata. + database.execSQL("UPDATE metadata SET seen=1 WHERE thingType=10") + database.execSQL("DROP TABLE lessons") + database.execSQL("DROP TABLE lessonChanges") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration74.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration74.kt new file mode 100644 index 00000000..1be5c212 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration74.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration74 : Migration(73, 74) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("""CREATE TABLE librusLessons ( + profileId INTEGER NOT NULL, + lessonId INTEGER NOT NULL, + teacherId INTEGER NOT NULL, + subjectId INTEGER NOT NULL, + teamId INTEGER, + PRIMARY KEY(profileId, lessonId))""") + + database.execSQL("CREATE INDEX index_librusLessons_profileId ON librusLessons (profileId)") + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration75.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration75.kt new file mode 100644 index 00000000..ed558115 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/migration/Migration75.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-1-25 + */ + +package pl.szczodrzynski.edziennik.data.db.migration + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +class Migration75 : Migration(74, 75) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE timetable RENAME TO _timetable") + database.execSQL("CREATE TABLE timetable (profileId INTEGER NOT NULL,id INTEGER NOT NULL,type INTEGER NOT NULL,date TEXT DEFAULT NULL,lessonNumber INTEGER DEFAULT NULL,startTime TEXT DEFAULT NULL,endTime TEXT DEFAULT NULL,subjectId INTEGER DEFAULT NULL,teacherId INTEGER DEFAULT NULL,teamId INTEGER DEFAULT NULL,classroom TEXT DEFAULT NULL,oldDate TEXT DEFAULT NULL,oldLessonNumber INTEGER DEFAULT NULL,oldStartTime TEXT DEFAULT NULL,oldEndTime TEXT DEFAULT NULL,oldSubjectId INTEGER DEFAULT NULL,oldTeacherId INTEGER DEFAULT NULL,oldTeamId INTEGER DEFAULT NULL,oldClassroom TEXT DEFAULT NULL,PRIMARY KEY(profileId, id))") + database.execSQL("INSERT INTO timetable (profileId, id, type, date, lessonNumber, startTime, endTime, subjectId, teacherId, teamId, classroom, oldDate, oldLessonNumber, oldStartTime, oldEndTime, oldSubjectId, oldTeacherId, oldTeamId, oldClassroom) SELECT profileId, id, type, date, lessonNumber, startTime, endTime, subjectId, teacherId, teamId, classroom, oldDate, oldLessonNumber, oldStartTime, oldEndTime, oldSubjectId, oldTeacherId, oldTeamId, oldClassroom FROM _timetable") + database.execSQL("DROP TABLE _timetable") + database.execSQL("CREATE INDEX index_lessons_profileId_type_date ON timetable (profileId, type, date)") + database.execSQL("CREATE INDEX index_lessons_profileId_type_oldDate ON timetable (profileId, type, oldDate)") + } +}