From 08657c1599b5a23a885542c5c66448cd4c49f3ee Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 31 Oct 2025 15:25:55 +0100 Subject: [PATCH] Fix migration 47.php (convert IPs) --- system/libs/pot/OTS_DB_MySQL.php | 1 + system/migrations/47.php | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/system/libs/pot/OTS_DB_MySQL.php b/system/libs/pot/OTS_DB_MySQL.php index 8b9626d9..24ee99dc 100644 --- a/system/libs/pot/OTS_DB_MySQL.php +++ b/system/libs/pot/OTS_DB_MySQL.php @@ -277,6 +277,7 @@ class OTS_DB_MySQL extends OTS_Base_DB 'field' => $result['Field'], 'type' => $result['Type'], 'null' => strtolower($result['Null']), + 'key' => strtolower($result['Key'] ?? ''), 'default' => $result['Default'], 'extra' => $result['Extra'], ]; diff --git a/system/migrations/47.php b/system/migrations/47.php index ea98d6f2..5cc433fb 100644 --- a/system/migrations/47.php +++ b/system/migrations/47.php @@ -6,20 +6,35 @@ // 2025-02-27 // remove ipv6, change to ip (for both ipv4 + ipv6) as VARCHAR(45) $up = function () use ($db) { - $db->query("ALTER TABLE `myaac_account_actions` DROP KEY `account_id`;"); - $db->query("ALTER TABLE `myaac_account_actions` ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`);"); + $accountActionsInfo = $db->getColumnInfo(TABLE_PREFIX . 'account_actions', 'account_id'); + if ($accountActionsInfo && is_array($accountActionsInfo) && $accountActionsInfo['key'] == 'pri') { + $db->query("ALTER TABLE `myaac_account_actions` DROP KEY `account_id`;"); + } + + if (!$db->hasColumn(TABLE_PREFIX . 'account_actions', 'id')) { + $db->addColumn(TABLE_PREFIX . 'account_actions', 'id', 'INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)'); + } $db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "VARCHAR(45) NOT NULL DEFAULT ''"); $db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET_NTOA(`ip`) WHERE `ip` != '0';"); $db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET6_NTOA(`ipv6`) WHERE `ip` = '0';"); - $db->dropColumn(TABLE_PREFIX . 'account_actions', 'ipv6'); + + if ($db->hasColumn(TABLE_PREFIX . 'account_actions', 'ipv6')) { + $db->dropColumn(TABLE_PREFIX . 'account_actions', 'ipv6'); + } }; $down = function () use ($db) { - $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` DROP `id`;"); + if ($db->hasColumn(TABLE_PREFIX . 'account_actions', 'id')) { + $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` DROP `id`;"); + } + $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` ADD KEY (`account_id`);"); - $db->addColumn(TABLE_PREFIX . 'account_actions', 'ipv6', "BINARY(16) NOT NULL DEFAULT 0x00000000000000000000000000000000 AFTER ip"); + if (!$db->hasColumn(TABLE_PREFIX . 'account_actions', 'ipv6')) { + $db->addColumn(TABLE_PREFIX . 'account_actions', 'ipv6', "BINARY(16) NOT NULL DEFAULT 0x00000000000000000000000000000000 AFTER ip"); + } + $db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ipv6` = INET6_ATON(ip) WHERE NOT IS_IPV4(`ip`);"); $db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET_ATON(`ip`) WHERE IS_IPV4(`ip`);"); $db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = 0 WHERE `ipv6` != 0x00000000000000000000000000000000;");