# HG changeset patch # User Matthew Wild # Date 1306978226 -3600 # Node ID c806a599224ace5e4ada6bafebb678054d95b705 # Parent 20979f124ad90d5b84ac56d7851d8845d7bf289c mod_storage_sql: Switch to MEDIUMTEXT for the 'value' column when using MySQL, as it imposes a 64K limit otherwise, potentially truncating data. Automatically upgrades existing tables. diff -r 20979f124ad9 -r c806a599224a plugins/mod_storage_sql.lua --- a/plugins/mod_storage_sql.lua Thu Jun 02 05:36:15 2011 +0500 +++ b/plugins/mod_storage_sql.lua Thu Jun 02 02:30:26 2011 +0100 @@ -68,6 +68,8 @@ local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; if params.driver == "PostgreSQL" then create_sql = create_sql:gsub("`", "\""); + elseif params.driver == "MySQL" then + create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT"); end local stmt = connection:prepare(create_sql); @@ -91,6 +93,22 @@ if not(ok and commit_ok) then module:log("warn", "Failed to create index (%s), lookups may not be optimised", err or commit_err); end + else -- COMPAT: Upgrade tables from 0.8.0 + -- Failed to create, but check existing MySQL table here + local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); + local ok = stmt:execute(); + local commit_ok = connection:commit(); + if ok and commit_ok then + if stmt:rowcount() > 0 then + local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); + local ok = stmt:execute(); + local commit_ok = connection:commit(); + if ok and commit_ok then + module:log("info", "Database table automatically upgraded"); + end + end + repeat until not stmt:fetch(); + end end end end