idac: updated scripts + bugfixes, BACKUP DATABASE!
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- WARNING: This script is NOT idempotent! MAKE A BACKUP BEFORE RUNNING THIS SCRIPT!
|
||||
|
||||
-- Drop UK idac_user_vs_info_uk
|
||||
ALTER TABLE idac_user_vs_info
|
||||
DROP FOREIGN KEY idac_user_vs_info_ibfk_1,
|
||||
@@ -30,19 +32,22 @@ 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 COLUMN boost_flag INT;
|
||||
|
||||
-- Delete the data from the original table where group_key is NULL
|
||||
DELETE FROM idac_user_vs_info
|
||||
WHERE group_key IS NULL;
|
||||
|
||||
-- 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(FLOOR(RAND()*(99999999999999-10000000000000+1)+10000000000000), 'A69E01A8888'), 0, 0, course_id, 0, 0, vs_cnt, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
FROM idac_user_vs_course_info;
|
||||
|
||||
-- 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;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- WARNING: This script is NOT idempotent! MAKE A BACKUP BEFORE RUNNING THIS SCRIPT!
|
||||
|
||||
-- Create the new table idac_user_vs_course_info
|
||||
CREATE TABLE idac_user_vs_course_info (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
@@ -41,7 +43,6 @@ 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,
|
||||
@@ -49,6 +50,19 @@ ADD COLUMN str INT DEFAULT 0,
|
||||
ADD COLUMN str_now INT DEFAULT 0,
|
||||
ADD COLUMN lose_now INT DEFAULT 0;
|
||||
|
||||
-- Create a temporary table to store the records you want to keep
|
||||
CREATE TEMPORARY TABLE temp_table AS
|
||||
SELECT MIN(id) AS min_id
|
||||
FROM idac_user_vs_info
|
||||
GROUP BY battle_mode, user;
|
||||
|
||||
-- Delete records from the original table based on the temporary table
|
||||
DELETE FROM idac_user_vs_info
|
||||
WHERE id NOT IN (SELECT min_id FROM temp_table);
|
||||
|
||||
-- Drop the temporary table
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_table;
|
||||
|
||||
-- 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,
|
||||
|
||||
Reference in New Issue
Block a user