From 731bc229d356270c5c2ca985ae1278152c544495 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:56:49 +0200 Subject: [PATCH] 1.4.2b - Fixed migrations for mysql 5.x --- CS2-SimpleAdmin.cs | 2 +- .../004_MoveOldFlagsToFlagsTable.sql | 53 ++++++++++--------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index 19b330a..cb35df1 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -37,7 +37,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)"); public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy & Dliix66"; - public override string ModuleVersion => "1.4.2a"; + public override string ModuleVersion => "1.4.2b"; public CS2_SimpleAdminConfig Config { get; set; } = new(); diff --git a/Database/Migrations/004_MoveOldFlagsToFlagsTable.sql b/Database/Migrations/004_MoveOldFlagsToFlagsTable.sql index 5a6af3c..71ca42b 100644 --- a/Database/Migrations/004_MoveOldFlagsToFlagsTable.sql +++ b/Database/Migrations/004_MoveOldFlagsToFlagsTable.sql @@ -1,33 +1,36 @@ INSERT INTO sa_admins_flags (admin_id, flag) -WITH RECURSIVE numbers AS ( - SELECT 1 AS n - UNION ALL - SELECT n + 1 FROM numbers - WHERE n < (SELECT MAX(CHAR_LENGTH(flags) - CHAR_LENGTH(REPLACE(flags, ',', '')) + 1) FROM sa_admins) -) SELECT min_admins.admin_id, TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(sa_admins.flags, ',', numbers.n), ',', -1)) AS flag -FROM numbers -INNER JOIN ( +FROM ( SELECT MIN(id) AS admin_id, player_steamid, server_id FROM sa_admins WHERE player_steamid != 'Console' GROUP BY player_steamid, server_id -) AS min_admins ON 1=1 -INNER JOIN sa_admins ON CHAR_LENGTH(sa_admins.flags) - CHAR_LENGTH(REPLACE(sa_admins.flags, ',', '')) >= numbers.n - 1 - AND min_admins.player_steamid = sa_admins.player_steamid - AND (min_admins.server_id = sa_admins.server_id OR (min_admins.server_id IS NULL AND sa_admins.server_id IS NULL)) - -UNION - -SELECT - (SELECT MAX(id) + 1 FROM sa_admins WHERE server_id IS NULL) AS admin_id, - TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(sa_admins.flags, ',', numbers.n), ',', -1)) AS flag -FROM numbers -INNER JOIN sa_admins ON CHAR_LENGTH(sa_admins.flags) - CHAR_LENGTH(REPLACE(sa_admins.flags, ',', '')) >= numbers.n - 1 - AND sa_admins.server_id IS NULL -WHERE sa_admins.player_steamid != 'Console' -AND EXISTS ( - SELECT 1 FROM sa_admins WHERE id = (SELECT MAX(id) + 1 FROM sa_admins WHERE server_id IS NULL) -); +) AS min_admins +JOIN sa_admins ON min_admins.player_steamid = sa_admins.player_steamid +JOIN ( + SELECT 1 AS n UNION ALL + SELECT 2 UNION ALL + SELECT 3 UNION ALL + SELECT 4 UNION ALL + SELECT 5 UNION ALL + SELECT 6 UNION ALL + SELECT 7 UNION ALL + SELECT 8 UNION ALL + SELECT 9 UNION ALL + SELECT 10 UNION ALL + SELECT 11 UNION ALL + SELECT 12 UNION ALL + SELECT 13 UNION ALL + SELECT 14 UNION ALL + SELECT 15 UNION ALL + SELECT 16 UNION ALL + SELECT 17 UNION ALL + SELECT 18 UNION ALL + SELECT 19 UNION ALL + SELECT 20 +) AS numbers +ON CHAR_LENGTH(sa_admins.flags) - CHAR_LENGTH(REPLACE(sa_admins.flags, ',', '')) >= numbers.n - 1 +AND (min_admins.server_id = sa_admins.server_id OR (min_admins.server_id IS NULL AND sa_admins.server_id IS NULL)) +WHERE sa_admins.id IS NOT NULL;