idac: added basic update/rollback scripts

This commit is contained in:
Dniel97 2024-01-08 16:45:43 +01:00
parent 62937584bc
commit e08acf8ee4
Signed by untrusted user: Dniel97
GPG Key ID: 6180B3C768FB2E08
3 changed files with 107 additions and 1 deletions

View File

@ -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;

View File

@ -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;

View File

@ -9,4 +9,4 @@ database = IDACData
reader = IDACReader
frontend = IDACFrontend
game_codes = [IDACConstants.GAME_CODE]
current_schema_version = 1
current_schema_version = 2