From e08acf8ee49b5bad9479c96a1ef5c8cdf557c74a Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Mon, 8 Jan 2024 16:45:43 +0100 Subject: [PATCH] idac: added basic update/rollback scripts --- core/data/schema/versions/SDGT_1_rollback.sql | 49 ++++++++++++++++ core/data/schema/versions/SDGT_2_upgrade.sql | 57 +++++++++++++++++++ titles/idac/__init__.py | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 core/data/schema/versions/SDGT_1_rollback.sql create mode 100644 core/data/schema/versions/SDGT_2_upgrade.sql diff --git a/core/data/schema/versions/SDGT_1_rollback.sql b/core/data/schema/versions/SDGT_1_rollback.sql new file mode 100644 index 0000000..307eaf8 --- /dev/null +++ b/core/data/schema/versions/SDGT_1_rollback.sql @@ -0,0 +1,49 @@ +SET FOREIGN_KEY_CHECKS=0; + +-- Drop UK idac_user_vs_info_uk +ALTER TABLE idac_user_vs_info +DROP FOREIGN KEY idac_user_vs_info_ibfk_1, +DROP INDEX idac_user_vs_info_uk; + +-- Drop the new columns added to the original table +ALTER TABLE idac_user_vs_info +DROP COLUMN battle_mode, +DROP COLUMN invalid, +DROP COLUMN str, +DROP COLUMN str_now, +DROP COLUMN lose_now; + +-- Add back the old columns to the original table +ALTER TABLE idac_user_vs_info +ADD COLUMN group_key VARCHAR(25), +ADD COLUMN win_flg INT, +ADD COLUMN style_car_id INT, +ADD COLUMN course_id INT, +ADD COLUMN course_day INT, +ADD COLUMN players_num INT, +ADD COLUMN winning INT, +ADD COLUMN advantage_1 INT, +ADD COLUMN advantage_2 INT, +ADD COLUMN advantage_3 INT, +ADD COLUMN advantage_4 INT, +ADD COLUMN select_course_id INT, +ADD COLUMN select_course_day INT, +ADD COLUMN select_course_random INT, +ADD COLUMN matching_success_sec INT, +ADD COLUMN boost_flag INT, +ADD COLUMN vs_history INT; + +-- Add back the constraints and indexes to the original table +ALTER TABLE idac_user_vs_info +ADD CONSTRAINT idac_user_vs_info_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE ON UPDATE CASCADE, +ADD UNIQUE KEY idac_user_vs_info_uk (user, group_key); + +-- Insert data back to the original table from idac_user_vs_course_info +INSERT INTO idac_user_vs_info (user, group_key, win_flg, style_car_id, course_id, course_day, players_num, winning, advantage_1, advantage_2, advantage_3, advantage_4, select_course_id, select_course_day, select_course_random, matching_success_sec, boost_flag, vs_history, break_count, break_penalty_flag) +SELECT user, CONCAT(DATE_FORMAT(NOW(), '%Y%m%d%H%i%s'), 'A69E01A8888'), 0, 0, course_id, 0, 0, vs_cnt, 0, 0, 0, 0, 0, 0, 0, 0, 0, vs_win, 0, 0 +FROM idac_user_vs_course_info; + +-- Drop the new table idac_user_vs_course_info +DROP TABLE IF EXISTS idac_user_vs_course_info; + +SET FOREIGN_KEY_CHECKS=1; diff --git a/core/data/schema/versions/SDGT_2_upgrade.sql b/core/data/schema/versions/SDGT_2_upgrade.sql new file mode 100644 index 0000000..8c4f626 --- /dev/null +++ b/core/data/schema/versions/SDGT_2_upgrade.sql @@ -0,0 +1,57 @@ +SET FOREIGN_KEY_CHECKS=0; + +-- Create the new table idac_user_vs_course_info +CREATE TABLE idac_user_vs_course_info ( + id INT PRIMARY KEY AUTO_INCREMENT, + user INT, + battle_mode INT, + course_id INT, + vs_cnt INT, + vs_win INT, + CONSTRAINT idac_user_vs_course_info_fk FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE ON UPDATE CASCADE, + UNIQUE KEY idac_user_vs_course_info_uk (user, battle_mode, course_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Insert data from the original table to the new tables +INSERT INTO idac_user_vs_course_info (user, battle_mode, course_id, vs_cnt, vs_win) +SELECT user, 1 as battle_mode, course_id, COUNT(winning) as vs_cnt, SUM(win_flg) as vs_win +FROM idac_user_vs_info +GROUP BY user, course_id; + +-- Drop UK idac_user_vs_info_uk +ALTER TABLE idac_user_vs_info +DROP FOREIGN KEY idac_user_vs_info_ibfk_1, +DROP INDEX idac_user_vs_info_uk; + +-- Drop/Add the old columns from the original table +ALTER TABLE idac_user_vs_info +DROP COLUMN group_key, +DROP COLUMN win_flg, +DROP COLUMN style_car_id, +DROP COLUMN course_id, +DROP COLUMN course_day, +DROP COLUMN players_num, +DROP COLUMN winning, +DROP COLUMN advantage_1, +DROP COLUMN advantage_2, +DROP COLUMN advantage_3, +DROP COLUMN advantage_4, +DROP COLUMN select_course_id, +DROP COLUMN select_course_day, +DROP COLUMN select_course_random, +DROP COLUMN matching_success_sec, +DROP COLUMN boost_flag, +DROP COLUMN vs_history, + +ADD COLUMN battle_mode TINYINT UNSIGNED DEFAULT 1 NOT NULL AFTER user, +ADD COLUMN invalid INT DEFAULT 0, +ADD COLUMN str INT DEFAULT 0, +ADD COLUMN str_now INT DEFAULT 0, +ADD COLUMN lose_now INT DEFAULT 0; + +-- Add UK idac_user_vs_info_uk +ALTER TABLE idac_user_vs_info +ADD CONSTRAINT idac_user_vs_info_ibfk_1 FOREIGN KEY (user) REFERENCES aime_user(id) ON DELETE CASCADE ON UPDATE CASCADE, +ADD UNIQUE KEY idac_user_vs_info_uk (user, battle_mode); + +SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file diff --git a/titles/idac/__init__.py b/titles/idac/__init__.py index 0c632bd..3b8a6ec 100644 --- a/titles/idac/__init__.py +++ b/titles/idac/__init__.py @@ -9,4 +9,4 @@ database = IDACData reader = IDACReader frontend = IDACFrontend game_codes = [IDACConstants.GAME_CODE] -current_schema_version = 1 +current_schema_version = 2