diff --git a/libs/pandautils/src/main/java/com/instructure/pandautils/room/offline/OfflineDatabaseMigrations.kt b/libs/pandautils/src/main/java/com/instructure/pandautils/room/offline/OfflineDatabaseMigrations.kt index 470d1fdafe..c80837d6b6 100644 --- a/libs/pandautils/src/main/java/com/instructure/pandautils/room/offline/OfflineDatabaseMigrations.kt +++ b/libs/pandautils/src/main/java/com/instructure/pandautils/room/offline/OfflineDatabaseMigrations.kt @@ -17,14 +17,23 @@ package com.instructure.pandautils.room.offline -import androidx.room.migration.Migration import com.instructure.pandautils.room.createMigration val offlineDatabaseMigrations = arrayOf( createMigration(1, 2) { database -> //CourseSyncProgressEntity - database.execSQL("ALTER TABLE CourseSyncProgressEntity DROP COLUMN workerId") + database.execSQL("CREATE TABLE IF NOT EXISTS `CourseSyncProgressEntity_temp` (`courseId` INTEGER NOT NULL," + + "`courseName` TEXT NOT NULL," + + "`tabs` TEXT NOT NULL," + + "`additionalFilesStarted` INTEGER NOT NULL," + + "`progressState` TEXT NOT NULL, PRIMARY KEY(`courseId`))") + database.execSQL( + "INSERT INTO CourseSyncProgressEntity_temp (courseId, courseName, tabs, additionalFilesStarted, progressState) " + + "SELECT courseId, courseName, tabs, additionalFilesStarted, progressState FROM CourseSyncProgressEntity" + ) + database.execSQL("DROP TABLE CourseSyncProgressEntity") + database.execSQL("ALTER TABLE CourseSyncProgressEntity_temp RENAME TO CourseSyncProgressEntity") //FileSyncProgressEntity database.execSQL( @@ -48,33 +57,41 @@ val offlineDatabaseMigrations = arrayOf( database.execSQL("ALTER TABLE FileSyncProgressEntity_temp RENAME TO FileSyncProgressEntity") //LockInfoEntity - database.execSQL("CREATE TABLE IF NOT EXISTS `LockInfoEntity_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + - "`modulePrerequisiteNames` TEXT," + - "`unlockAt` TEXT," + - "`lockedModuleId` INTEGER," + - "`assignmentId` INTEGER," + - "`moduleId` INTEGER," + - "`pageId` INTEGER," + - "FOREIGN KEY(`moduleId`) REFERENCES `ModuleContentDetailsEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - "FOREIGN KEY(`assignmentId`) REFERENCES `AssignmentEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - "FOREIGN KEY(`pageId`) REFERENCES `PageEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)") - database.execSQL("INSERT INTO LockInfoEntity_temp (id, modulePrerequisiteNames, unlockAt, lockedModuleId, assignmentId, moduleId, pageId) " + - "SELECT id, modulePrerequisiteNames, unlockAt, lockedModuleId, assignmentId, moduleId, pageId FROM LockInfoEntity") + database.execSQL( + "CREATE TABLE IF NOT EXISTS `LockInfoEntity_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + + "`modulePrerequisiteNames` TEXT," + + "`unlockAt` TEXT," + + "`lockedModuleId` INTEGER," + + "`assignmentId` INTEGER," + + "`moduleId` INTEGER," + + "`pageId` INTEGER," + + "FOREIGN KEY(`moduleId`) REFERENCES `ModuleContentDetailsEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + "FOREIGN KEY(`assignmentId`) REFERENCES `AssignmentEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + "FOREIGN KEY(`pageId`) REFERENCES `PageEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)" + ) + database.execSQL( + "INSERT INTO LockInfoEntity_temp (id, modulePrerequisiteNames, unlockAt, lockedModuleId, assignmentId, moduleId, pageId) " + + "SELECT id, modulePrerequisiteNames, unlockAt, lockedModuleId, assignmentId, moduleId, pageId FROM LockInfoEntity" + ) database.execSQL("DROP TABLE LockInfoEntity") database.execSQL("ALTER TABLE LockInfoEntity_temp RENAME TO LockInfoEntity") //LockedModuleEntity - database.execSQL("CREATE TABLE IF NOT EXISTS `LockedModuleEntity_temp` (" + - "`id` INTEGER NOT NULL," + - "`contextId` INTEGER NOT NULL," + - "`contextType` TEXT," + - "`name` TEXT," + - "`unlockAt` TEXT," + - "`isRequireSequentialProgress` INTEGER NOT NULL," + - "`lockInfoId` INTEGER, PRIMARY KEY(`id`)," + - "FOREIGN KEY(`lockInfoId`) REFERENCES `LockInfoEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )") - database.execSQL("INSERT INTO LockedModuleEntity_temp (id, contextId, contextType, name, unlockAt, isRequireSequentialProgress) " + - "SELECT id, contextId, contextType, name, unlockAt, isRequireSequentialProgress FROM LockedModuleEntity") + database.execSQL( + "CREATE TABLE IF NOT EXISTS `LockedModuleEntity_temp` (" + + "`id` INTEGER NOT NULL," + + "`contextId` INTEGER NOT NULL," + + "`contextType` TEXT," + + "`name` TEXT," + + "`unlockAt` TEXT," + + "`isRequireSequentialProgress` INTEGER NOT NULL," + + "`lockInfoId` INTEGER, PRIMARY KEY(`id`)," + + "FOREIGN KEY(`lockInfoId`) REFERENCES `LockInfoEntity`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )" + ) + database.execSQL( + "INSERT INTO LockedModuleEntity_temp (id, contextId, contextType, name, unlockAt, isRequireSequentialProgress) " + + "SELECT id, contextId, contextType, name, unlockAt, isRequireSequentialProgress FROM LockedModuleEntity" + ) database.execSQL("DROP TABLE LockedModuleEntity") database.execSQL("ALTER TABLE LockedModuleEntity_temp RENAME TO LockedModuleEntity") },