aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-10-11 19:23:21 +0100
committerMatthew Wild <mwild1@gmail.com>2018-10-11 19:23:21 +0100
commit23ebd922f22234f220d3cb90031bb92521915047 (patch)
treefa3962c951ffdee392ac72f827119eb942f845eb /plugins
parent260734d1fc28535c1dd6544292b9a0cdfdc39afc (diff)
downloadprosody-23ebd922f22234f220d3cb90031bb92521915047.tar.gz
prosody-23ebd922f22234f220d3cb90031bb92521915047.zip
mod_storage_sql: Change prosodyarchive_index to be non-unique (fixes #1087)
MySQL requires that the first 20 bytes are unique, even if they differ after the first 20 bytes. This breaks e.g. pubsub/PEP nodes longer than 20 characters that have common prefixes.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua33
1 files changed, 25 insertions, 8 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 5f02aa06..872b5f49 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -496,7 +496,7 @@ local function create_table(engine) -- luacheck: ignore 431/engine
Column { name="with", type="TEXT", nullable=false }; -- related id
Column { name="type", type="TEXT", nullable=false };
Column { name="value", type="MEDIUMTEXT", nullable=false };
- Index { name="prosodyarchive_index", unique = true, "host", "user", "store", "key" };
+ Index { name="prosodyarchive_index", "host", "user", "store", "key" };
Index { name="prosodyarchive_with_when", "host", "user", "store", "with", "when" };
Index { name="prosodyarchive_when", "host", "user", "store", "when" };
};
@@ -509,13 +509,30 @@ local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore
local changes = false;
if params.driver == "MySQL" then
local success,err = engine:transaction(function()
- local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'");
- if result:rowcount() > 0 then
- changes = true;
- if apply_changes then
- module:log("info", "Upgrading database schema...");
- engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT");
- module:log("info", "Database table automatically upgraded");
+ do
+ local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'");
+ if result:rowcount() > 0 then
+ changes = true;
+ if apply_changes then
+ module:log("info", "Upgrading database schema (value column size)...");
+ engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT");
+ module:log("info", "Database table automatically upgraded");
+ end
+ end
+ end
+
+ do
+ -- Ensure index is not unique (issue #1087)
+ local result = assert(engine:execute([[SHOW INDEX FROM prosodyarchive WHERE key_name='prosodyarchive_index' and non_unique=0]]));
+ if result:rowcount() > 0 then
+ changes = true;
+ if apply_changes then
+ module:log("info", "Upgrading database schema (prosodyarchive_index)...");
+ engine:execute[[ALTER TABLE "prosodyarchive" DROP INDEX prosodyarchive_index;]];
+ local new_index = sql.Index { table = "prosodyarchive", name="prosodyarchive_index", "host", "user", "store", "key" };
+ engine:_create_index(new_index);
+ module:log("info", "Database table automatically upgraded");
+ end
end
end
return true;