aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2025-04-09 18:27:42 +0200
committerKim Alvefur <zash@zash.se>2025-04-09 18:27:42 +0200
commit4eb0e47d075bf4fab52e02b16c846e89f97298b5 (patch)
tree3485e4e36b7134da7242b5377172ee9c3c506032
parent629b5b10b5e1eb786606ba5e84a0078ce0f8427a (diff)
downloadprosody-4eb0e47d075bf4fab52e02b16c846e89f97298b5.tar.gz
prosody-4eb0e47d075bf4fab52e02b16c846e89f97298b5.zip
mod_storage_sql: Handle failure to deploy new UNIQUE index
Somehow a user ended up with duplicate data preventing creation of the new unique index needed for UPSERT (see 3ec48555b773). This should eventually self-heal #1918 if the duplicate data is replaced by the older DELETE + INSERT method. Without any index at all, it will be slower.
-rw-r--r--plugins/mod_storage_sql.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 25737a35..ee43905a 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -46,11 +46,11 @@ end
local function has_upsert(engine)
if engine.params.driver == "SQLite3" then
-- SQLite3 >= 3.24.0
- return engine.sqlite_version and (engine.sqlite_version[2] or 0) >= 24;
+ return engine.sqlite_version and (engine.sqlite_version[2] or 0) >= 24 and engine.has_upsert_index;
elseif engine.params.driver == "PostgreSQL" then
-- PostgreSQL >= 9.5
-- Versions without support have long since reached end of life.
- return true;
+ return engine.has_upsert_index;
end
-- We don't support UPSERT on MySQL/MariaDB, they seem to have a completely different syntax, uncertaint from which versions.
return false
@@ -898,8 +898,10 @@ local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore
end
end
if not indices["prosody_unique_index"] then
- module:log("error", "New index \"prosody_unique_index\" does not exist!");
- return false;
+ module:log("warn", "Index \"prosody_unique_index\" does not exist, performance may be worse than normal!");
+ engine.has_upsert_index = false;
+ else
+ engine.has_upsert_index = true;
end
end
return changes;