diff options
author | Sadie Powell <sadie@witchery.services> | 2024-11-16 12:09:08 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-11-16 12:13:17 +0000 |
commit | 240f8b9e505af4888039769f5ce5a2388bdf228e (patch) | |
tree | a767905600bf9f35dfe7c205526daf2d51207305 /modules/extra/mysql.cpp | |
parent | 656ca80dd037e20b31dbbb7449bca1252924d86e (diff) |
Halt the column migration if any of the queries fail.
Diffstat (limited to 'modules/extra/mysql.cpp')
-rw-r--r-- | modules/extra/mysql.cpp | 28 |
1 files 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<Query> 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())); + } + + 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())); + } - 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(); } } } |