# HG changeset patch # User Kim Alvefur # Date 1744216062 -7200 # Node ID c600794cafb6d8d055e671009ec044d2443ea724 # Parent a4b58ea5bf7b62874167c9a24f440282cc2cbb14 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. diff -r a4b58ea5bf7b -r c600794cafb6 plugins/mod_storage_sql.lua --- a/plugins/mod_storage_sql.lua Wed Apr 09 18:11:57 2025 +0200 +++ b/plugins/mod_storage_sql.lua Wed Apr 09 18:27:42 2025 +0200 @@ -46,11 +46,11 @@ 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 @@ 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;