diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-10-11 19:23:21 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-10-11 19:23:21 +0100 |
commit | 9ddebb7bbfb3334492251804feb8097b204e205f (patch) | |
tree | fa3962c951ffdee392ac72f827119eb942f845eb | |
parent | 23fd5679ed5e182b05cba815d1fb2e2cbd6959b4 (diff) | |
download | prosody-9ddebb7bbfb3334492251804feb8097b204e205f.tar.gz prosody-9ddebb7bbfb3334492251804feb8097b204e205f.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.
-rw-r--r-- | plugins/mod_storage_sql.lua | 33 |
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; |