Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 9493:55b40f3fa659
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.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Oct 2018 19:23:21 +0100 |
parent | 9492:c03c60a2dede |
child | 9500:7de89d66cbb9 |
comparison
equal
deleted
inserted
replaced
9492:c03c60a2dede | 9493:55b40f3fa659 |
---|---|
494 Column { name="key", type="TEXT", nullable=false }; -- item id | 494 Column { name="key", type="TEXT", nullable=false }; -- item id |
495 Column { name="when", type="INTEGER", nullable=false }; -- timestamp | 495 Column { name="when", type="INTEGER", nullable=false }; -- timestamp |
496 Column { name="with", type="TEXT", nullable=false }; -- related id | 496 Column { name="with", type="TEXT", nullable=false }; -- related id |
497 Column { name="type", type="TEXT", nullable=false }; | 497 Column { name="type", type="TEXT", nullable=false }; |
498 Column { name="value", type="MEDIUMTEXT", nullable=false }; | 498 Column { name="value", type="MEDIUMTEXT", nullable=false }; |
499 Index { name="prosodyarchive_index", unique = true, "host", "user", "store", "key" }; | 499 Index { name="prosodyarchive_index", "host", "user", "store", "key" }; |
500 Index { name="prosodyarchive_with_when", "host", "user", "store", "with", "when" }; | 500 Index { name="prosodyarchive_with_when", "host", "user", "store", "with", "when" }; |
501 Index { name="prosodyarchive_when", "host", "user", "store", "when" }; | 501 Index { name="prosodyarchive_when", "host", "user", "store", "when" }; |
502 }; | 502 }; |
503 engine:transaction(function() | 503 engine:transaction(function() |
504 ProsodyArchiveTable:create(engine); | 504 ProsodyArchiveTable:create(engine); |
507 | 507 |
508 local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine | 508 local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine |
509 local changes = false; | 509 local changes = false; |
510 if params.driver == "MySQL" then | 510 if params.driver == "MySQL" then |
511 local success,err = engine:transaction(function() | 511 local success,err = engine:transaction(function() |
512 local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'"); | 512 do |
513 if result:rowcount() > 0 then | 513 local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'"); |
514 changes = true; | 514 if result:rowcount() > 0 then |
515 if apply_changes then | 515 changes = true; |
516 module:log("info", "Upgrading database schema..."); | 516 if apply_changes then |
517 engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT"); | 517 module:log("info", "Upgrading database schema (value column size)..."); |
518 module:log("info", "Database table automatically upgraded"); | 518 engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT"); |
519 module:log("info", "Database table automatically upgraded"); | |
520 end | |
521 end | |
522 end | |
523 | |
524 do | |
525 -- Ensure index is not unique (issue #1087) | |
526 local result = assert(engine:execute([[SHOW INDEX FROM prosodyarchive WHERE key_name='prosodyarchive_index' and non_unique=0]])); | |
527 if result:rowcount() > 0 then | |
528 changes = true; | |
529 if apply_changes then | |
530 module:log("info", "Upgrading database schema (prosodyarchive_index)..."); | |
531 engine:execute[[ALTER TABLE "prosodyarchive" DROP INDEX prosodyarchive_index;]]; | |
532 local new_index = sql.Index { table = "prosodyarchive", name="prosodyarchive_index", "host", "user", "store", "key" }; | |
533 engine:_create_index(new_index); | |
534 module:log("info", "Database table automatically upgraded"); | |
535 end | |
519 end | 536 end |
520 end | 537 end |
521 return true; | 538 return true; |
522 end); | 539 end); |
523 if not success then | 540 if not success then |