Mercurial > prosody-hg
comparison plugins/mod_storage_sql.lua @ 8083:32898a74b9d9
Merge 0.10->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 13 Apr 2017 01:30:24 +0200 |
| parents | 60207251863c 8ca11201bfe7 |
| children | 5c91fb62338e |
comparison
equal
deleted
inserted
replaced
| 8078:60207251863c | 8083:32898a74b9d9 |
|---|---|
| 460 | 460 |
| 461 local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine | 461 local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine |
| 462 local changes = false; | 462 local changes = false; |
| 463 if params.driver == "MySQL" then | 463 if params.driver == "MySQL" then |
| 464 local success,err = engine:transaction(function() | 464 local success,err = engine:transaction(function() |
| 465 local result = engine:execute("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); | 465 local result = engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'"); |
| 466 if result:rowcount() > 0 then | 466 if result:rowcount() > 0 then |
| 467 changes = true; | 467 changes = true; |
| 468 if apply_changes then | 468 if apply_changes then |
| 469 module:log("info", "Upgrading database schema..."); | 469 module:log("info", "Upgrading database schema..."); |
| 470 engine:execute("ALTER TABLE prosody MODIFY COLUMN \"value\" MEDIUMTEXT"); | 470 engine:execute("ALTER TABLE \"prosody\" MODIFY COLUMN \"value\" MEDIUMTEXT"); |
| 471 module:log("info", "Database table automatically upgraded"); | 471 module:log("info", "Database table automatically upgraded"); |
| 472 end | 472 end |
| 473 end | 473 end |
| 474 return true; | 474 return true; |
| 475 end); | 475 end); |
| 482 | 482 |
| 483 -- COMPAT w/pre-0.10: Upgrade table to UTF-8 if not already | 483 -- COMPAT w/pre-0.10: Upgrade table to UTF-8 if not already |
| 484 local check_encoding_query = [[ | 484 local check_encoding_query = [[ |
| 485 SELECT "COLUMN_NAME","COLUMN_TYPE","TABLE_NAME" | 485 SELECT "COLUMN_NAME","COLUMN_TYPE","TABLE_NAME" |
| 486 FROM "information_schema"."columns" | 486 FROM "information_schema"."columns" |
| 487 WHERE "TABLE_NAME" LIKE 'prosody%%' AND ( "CHARACTER_SET_NAME"!='%s' OR "COLLATION_NAME"!='%s_bin' ); | 487 WHERE "TABLE_NAME" LIKE 'prosody%%' |
| 488 ]]; | 488 AND "TABLE_SCHEMA" = ? |
| 489 check_encoding_query = check_encoding_query:format(engine.charset, engine.charset); | 489 AND ( "CHARACTER_SET_NAME"!=? OR "COLLATION_NAME"!=?); |
| 490 ]]; | |
| 490 -- FIXME Is it ok to ignore the return values from this? | 491 -- FIXME Is it ok to ignore the return values from this? |
| 491 engine:transaction(function() | 492 engine:transaction(function() |
| 492 local result = assert(engine:execute(check_encoding_query)); | 493 local result = assert(engine:execute(check_encoding_query, params.database, engine.charset, engine.charset.."_bin")); |
| 493 local n_bad_columns = result:rowcount(); | 494 local n_bad_columns = result:rowcount(); |
| 494 if n_bad_columns > 0 then | 495 if n_bad_columns > 0 then |
| 495 changes = true; | 496 changes = true; |
| 496 if apply_changes then | 497 if apply_changes then |
| 497 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); | 498 module:log("warn", "Found %d columns in prosody table requiring encoding change, updating now...", n_bad_columns); |
| 505 end | 506 end |
| 506 module:log("info", "Database encoding upgrade complete!"); | 507 module:log("info", "Database encoding upgrade complete!"); |
| 507 end | 508 end |
| 508 end | 509 end |
| 509 end); | 510 end); |
| 510 success,err = engine:transaction(function() return engine:execute(check_encoding_query); end); | 511 success,err = engine:transaction(function() |
| 512 return engine:execute(check_encoding_query, params.database, | |
| 513 engine.charset, engine.charset.."_bin"); | |
| 514 end); | |
| 511 if not success then | 515 if not success then |
| 512 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); | 516 module:log("error", "Failed to check/upgrade database encoding: %s", err or "unknown error"); |
| 513 return false; | 517 return false; |
| 514 end | 518 end |
| 515 end | 519 end |
