Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 9628:2fcf517b811e 0.11
mod_storage_sql: Catch errors during schema upgrade (thanks Nothing4You)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 21:55:16 +0000 |
parent | 9537:5fe1b08e6353 |
child | 9691:e11e076f0eb8 |
child | 10011:2408e6362c15 |
comparison
equal
deleted
inserted
replaced
9626:4d3ab7153153 | 9628:2fcf517b811e |
---|---|
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 do | 512 do |
513 local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'"); | 513 local result = assert(engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'")); |
514 if result:rowcount() > 0 then | 514 if result:rowcount() > 0 then |
515 changes = true; | 515 changes = true; |
516 if apply_changes then | 516 if apply_changes then |
517 module:log("info", "Upgrading database schema (value column size)..."); | 517 module:log("info", "Upgrading database schema (value column size)..."); |
518 engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT"); | 518 assert(engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT")); |
519 module:log("info", "Database table automatically upgraded"); | 519 module:log("info", "Database table automatically upgraded"); |
520 end | 520 end |
521 end | 521 end |
522 end | 522 end |
523 | 523 |
526 local result = assert(engine:execute([[SHOW INDEX FROM prosodyarchive WHERE key_name='prosodyarchive_index' and non_unique=0]])); | 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 | 527 if result:rowcount() > 0 then |
528 changes = true; | 528 changes = true; |
529 if apply_changes then | 529 if apply_changes then |
530 module:log("info", "Upgrading database schema (prosodyarchive_index)..."); | 530 module:log("info", "Upgrading database schema (prosodyarchive_index)..."); |
531 engine:execute[[ALTER TABLE "prosodyarchive" DROP INDEX prosodyarchive_index;]]; | 531 assert(engine:execute[[ALTER TABLE "prosodyarchive" DROP INDEX prosodyarchive_index;]]); |
532 local new_index = sql.Index { table = "prosodyarchive", name="prosodyarchive_index", "host", "user", "store", "key" }; | 532 local new_index = sql.Index { table = "prosodyarchive", name="prosodyarchive_index", "host", "user", "store", "key" }; |
533 engine:_create_index(new_index); | 533 assert(engine:_create_index(new_index)); |
534 module:log("info", "Database table automatically upgraded"); | 534 module:log("info", "Database table automatically upgraded"); |
535 end | 535 end |
536 end | 536 end |
537 end | 537 end |
538 return true; | 538 return true; |