From 2df35026db90b4afe416d43e5731e3685acf8a9f Mon Sep 17 00:00:00 2001 From: mvn23 Date: Sun, 15 Sep 2019 14:35:58 +0200 Subject: [PATCH] Fix mysql migration --- supysonic/schema/migration/mysql/20190915.sql | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/supysonic/schema/migration/mysql/20190915.sql b/supysonic/schema/migration/mysql/20190915.sql index 6b258e4..664fd3d 100644 --- a/supysonic/schema/migration/mysql/20190915.sql +++ b/supysonic/schema/migration/mysql/20190915.sql @@ -15,47 +15,46 @@ DROP INDEX index_rating_folder_rated_id_fk ON rating_folder; ALTER TABLE folder - ADD int_id INTEGER AFTER id, + ADD int_id INTEGER REFERENCES folder AFTER id, ADD int_parent_id INTEGER REFERENCES folder AFTER parent_id; -UPDATE folder SET int_id = (SELECT id FROM folder_id_to_int WHERE uuid == folder.id); -UPDATE folder SET int_parent_id = (SELECT id FROM folder_id_to_int WHERE uuid == folder.parent_id); +UPDATE folder SET int_id = (SELECT id FROM folder_id_to_int WHERE uuid = folder.id); +UPDATE folder SET int_parent_id = (SELECT id FROM folder_id_to_int WHERE uuid = folder.parent_id); ALTER TABLE folder DROP PRIMARY KEY, DROP COLUMN id, DROP COLUMN parent_id, - RENAME COLUMN int_id TO id, - RENAME COLUMN int_parent_id TO parent_id, - MODIFY id INTEGER AUTO_INCREMENT, + CHANGE COLUMN int_id id INTEGER AUTO_INCREMENT, + CHANGE COLUMN int_parent_id parent_id INTEGER, ADD PRIMARY KEY (id); ALTER TABLE track ADD int_root_folder_id INTEGER NOT NULL REFERENCES folder AFTER root_folder_id, ADD int_folder_id INTEGER NOT NULL REFERENCES folder AFTER folder_id; -UPDATE track SET int_root_folder_id = (SELECT id FROM folder_id_to_int WHERE uuid == track.root_folder_id); -UPDATE track SET int_folder_id = (SELECT id FROM folder_id_to_int WHERE uuid == track.folder_id); +UPDATE track SET int_root_folder_id = (SELECT id FROM folder_id_to_int WHERE uuid = track.root_folder_id); +UPDATE track SET int_folder_id = (SELECT id FROM folder_id_to_int WHERE uuid = track.folder_id); ALTER TABLE track DROP COLUMN root_folder_id, DROP COLUMN folder_id, - RENAME COLUMN int_root_folder_id TO root_folder_id, - RENAME COLUMN int_folder_id TO folder_id, + CHANGE COLUMN int_root_folder_id root_folder_id INTEGER NOT NULL, + CHANGE COLUMN int_folder_id folder_id INTEGER NOT NULL; ALTER TABLE starred_folder ADD int_starred_id INTEGER NOT NULL REFERENCES folder AFTER starred_id; -UPDATE starred_folder SET int_starred_id = (SELECT id FROM folder_id_to_int WHERE uuid == starred_folder.starred_id); +UPDATE starred_folder SET int_starred_id = (SELECT id FROM folder_id_to_int WHERE uuid = starred_folder.starred_id); ALTER TABLE starred_folder DROP PRIMARY KEY, DROP COLUMN starred_id, - RENAME COLUMN int_starred_id TO starred_id, + CHANGE COLUMN int_starred_id starred_id INTEGER NOT NULL, ADD PRIMARY KEY (user_id, starred_id); ALTER TABLE rating_folder ADD int_rated_id INTEGER NOT NULL REFERENCES folder AFTER rated_id; -UPDATE rating_folder SET int_rated_id = (SELECT id FROM folder_id_to_int WHERE uuid == rating_folder.rated_id); +UPDATE rating_folder SET int_rated_id = (SELECT id FROM folder_id_to_int WHERE uuid = rating_folder.rated_id); ALTER TABLE rating_folder DROP PRIMARY KEY, DROP COLUMN rated_id, - RENAME COLUMN int_rated_id TO rated_id, + CHANGE COLUMN int_rated_id rated_id INTEGER NOT NULL, ADD PRIMARY KEY (user_id, rated_id);