Software /
code /
prosody
Diff
plugins/mod_storage_sql.lua @ 13836:c600794cafb6 13.0
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 09 Apr 2025 18:27:42 +0200 |
parent | 13833:497efa2cbf2c |
child | 13838:a93e7310bfcd |
line wrap: on
line diff
--- 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;