Skip to content

Commit

Permalink
pre 14 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hermannakos committed Feb 2, 2024
1 parent 7c18fab commit fec71d1
Showing 1 changed file with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
},
Expand Down

0 comments on commit fec71d1

Please sign in to comment.