aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2011-06-02 02:31:18 +0100
committerMatthew Wild <mwild1@gmail.com>2011-06-02 02:31:18 +0100
commit3415a3da2add388452f19386d7b37bffec49a2a7 (patch)
tree5c18192e6e617619650e72e269b8fd1077770a69 /plugins/mod_storage_sql.lua
parentdc3512261a38f142b2c6d19b398f13dbb2af1f52 (diff)
parent7037ff8b95c6d1860b1ca9e42a9916ac237419cc (diff)
downloadprosody-3415a3da2add388452f19386d7b37bffec49a2a7.tar.gz
prosody-3415a3da2add388452f19386d7b37bffec49a2a7.zip
Merge 0.8->trunk
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r--plugins/mod_storage_sql.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index b88efb64..dd148704 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -68,6 +68,8 @@ local function create_table()
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 @@ local function create_table()
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