Last active
June 30, 2020 16:48
Star
You must be signed in to star a gist
Migration: copying data, rename table and relax FK constraints
This file contains 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
database.execSQL(""" | |
CREATE TABLE IF NOT EXISTS TrackCreator_temp ( | |
`track_id` TEXT NOT NULL, | |
`user_id` TEXT NOT NULL, | |
PRIMARY KEY(`track_id`, `user_id`), | |
FOREIGN KEY(`track_id`) REFERENCES `Track`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION , | |
FOREIGN KEY(`user_id`) REFERENCES `User`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION | |
) | |
""".trimIndent()) | |
// Move all data to temporary table | |
database.execSQL("INSERT INTO TrackCreator_temp SELECT * FROM TrackCreator") | |
// Drop mis-scheme table | |
database.execSQL("DROP TABLE TrackCreator") | |
// Rename temporary table to definitive name | |
database.execSQL("ALTER TABLE TrackCreator_temp RENAME TO TrackCreator") | |
// Recreate indexes if needed (omitted for brevity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment