From 240f8b9e505af4888039769f5ce5a2388bdf228e Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 16 Nov 2024 12:09:08 +0000 Subject: [PATCH] Halt the column migration if any of the queries fail. --- modules/extra/mysql.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/extra/mysql.cpp b/modules/extra/mysql.cpp index 39b1ae1de..126714fb3 100644 --- a/modules/extra/mysql.cpp +++ b/modules/extra/mysql.cpp @@ -490,19 +490,31 @@ std::vector MySQLService::CreateTable(const Anope::string &table, const D if (update) { - // We an't just use MODIFY COLUMN here because the value may not + // We can't just use MODIFY COLUMN here because the value may not // be valid and we may need to replace with the default. - this->RunQuery(Anope::printf("ALTER TABLE `%s` ADD COLUMN `%s_new` %s; ", + auto res = this->RunQuery(Anope::printf("ALTER TABLE `%s` ADD COLUMN `%s_new` %s; ", table.c_str(), column.c_str(), GetColumn(stype).c_str())); - this->RunQuery(Anope::printf("UPDATE IGNORE `%s` SET `%s_new` = %s; ", - table.c_str(), column.c_str(), column.c_str())); + if (res) + { + res = this->RunQuery(Anope::printf("UPDATE IGNORE `%s` SET `%s_new` = %s; ", + table.c_str(), column.c_str(), column.c_str())); + } - this->RunQuery(Anope::printf("ALTER TABLE `%s` DROP COLUMN `%s`; ", - table.c_str(), column.c_str())); + if (res) + { + res = this->RunQuery(Anope::printf("ALTER TABLE `%s` DROP COLUMN `%s`; ", + table.c_str(), column.c_str())); + } - res = this->RunQuery(Anope::printf("ALTER TABLE `%s` RENAME COLUMN `%s_new` TO `%s`; ", - table.c_str(), column.c_str(), column.c_str())); + if (res) + { + res = this->RunQuery(Anope::printf("ALTER TABLE `%s` RENAME COLUMN `%s_new` TO `%s`; ", + table.c_str(), column.c_str(), column.c_str())); + } + + if (!res) + Log(LOG_DEBUG) << "Failed to migrate the " << column << " column: " << res.GetError(); } } }