Fix migration script

This commit is contained in:
jude 2024-08-11 16:57:48 +01:00
parent ef76611d33
commit 96dc80fef9

View File

@ -1,3 +1,5 @@
SET FOREIGN_KEY_CHECKS=0;
-- Tables no longer needed as old dashboard is decomm. -- Tables no longer needed as old dashboard is decomm.
DROP TABLE guild_users; DROP TABLE guild_users;
DROP TABLE events; DROP TABLE events;
@ -10,8 +12,6 @@ ALTER TABLE users DROP COLUMN `language`;
ALTER TABLE users DROP COLUMN `patreon`; ALTER TABLE users DROP COLUMN `patreon`;
ALTER TABLE users DROP COLUMN `name`; ALTER TABLE users DROP COLUMN `name`;
ALTER TABLE users DROP PRIMARY KEY, ADD PRIMARY KEY (`user`);
ALTER TABLE todos DROP CONSTRAINT todos_ibfk_5, MODIFY COLUMN user_id BIGINT UNSIGNED; ALTER TABLE todos DROP CONSTRAINT todos_ibfk_5, MODIFY COLUMN user_id BIGINT UNSIGNED;
UPDATE todos SET user_id = (SELECT user FROM users WHERE id = user_id); UPDATE todos SET user_id = (SELECT user FROM users WHERE id = user_id);
ALTER TABLE todos ADD CONSTRAINT todos_user_fk FOREIGN KEY (user_id) REFERENCES users(user); ALTER TABLE todos ADD CONSTRAINT todos_user_fk FOREIGN KEY (user_id) REFERENCES users(user);
@ -20,5 +20,8 @@ ALTER TABLE reminders DROP CONSTRAINT reminders_ibfk_2, MODIFY COLUMN set_by BIG
UPDATE reminders SET set_by = (SELECT user FROM users WHERE id = set_by); UPDATE reminders SET set_by = (SELECT user FROM users WHERE id = set_by);
ALTER TABLE reminders ADD CONSTRAINT reminder_user_fk FOREIGN KEY (set_by) REFERENCES users(user); ALTER TABLE reminders ADD CONSTRAINT reminder_user_fk FOREIGN KEY (set_by) REFERENCES users(user);
ALTER TABLE users DROP PRIMARY KEY, CHANGE id id INT UNSIGNED, ADD PRIMARY KEY (`user`);
ALTER TABLE users DROP COLUMN `id`; ALTER TABLE users DROP COLUMN `id`;
ALTER TABLE users RENAME COLUMN `user` TO `id`; ALTER TABLE users RENAME COLUMN `user` TO `id`;
SET FOREIGN_KEY_CHECKS=1;