From 4eb0e47d075bf4fab52e02b16c846e89f97298b5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 9 Apr 2025 18:27:42 +0200 Subject: 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. --- plugins/mod_storage_sql.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'plugins') 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; -- cgit v1.2.3