Created
August 4, 2020 12:59
-
-
Save Pekwerike/a5e288c56d125c371b9b6e5e434934f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val MIGRATION_3_4 = object : Migration(3, 4){ | |
override fun migrate(database: SupportSQLiteDatabase) { | |
//create new table | |
database.execSQL("CREATE TABLE `new_course_table`(`course_index_key` INTEGER NOT NULL," + | |
" `course_code` TEXT NOT NULL," + | |
" `course_title` TEXT NOT NULL, " + | |
"`course_unit` INTEGER NOT NULL," + | |
" `course_status` TEXT," + | |
" `course_date_added` INTEGER," + | |
" PRIMARY KEY(`course_index_key`) )") | |
//insert data from old table into new table | |
database.execSQL("INSERT INTO new_course_table(course_code," + | |
" course_title," + | |
" course_unit," + | |
" course_status," + | |
" course_date_added)" + | |
" SELECT course_code, course_title, course_unit, course_status, course_date_added FROM course_table") | |
//drop old table | |
database.execSQL("DROP TABLE course_table") | |
//rename new table to the old table name | |
database.execSQL("ALTER TABLE new_course_table RENAME TO course_table") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handling RoomDb Migration: Create a new primary key column in an existing entity