From 089b80680f8dc0e5d2249662c01012a819c94c23 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 11 Jun 2011 02:15:38 +0100 Subject: mod_storage_sql: Add sql_manage_tables to disable table creation/updating. --- plugins/mod_storage_sql.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 055d6599..59583def 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -65,6 +65,9 @@ local function connect() end local function create_table() + if not module:get_option("sql_manage_tables", true) then + return; + end 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("`", "\""); -- cgit v1.2.3 From 8ec24c7bf7bb143b106babeba5371f85c461f6d2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 11 Jun 2011 02:16:26 +0100 Subject: mod_storage_sql: Add extra logging and error handling around table creation --- plugins/mod_storage_sql.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 59583def..6a2d36f1 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -75,7 +75,7 @@ local function create_table() create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT"); end - local stmt = connection:prepare(create_sql); + local stmt, err = connection:prepare(create_sql); if stmt then local ok = stmt:execute(); local commit_ok = connection:commit(); @@ -103,18 +103,25 @@ local function create_table() local commit_ok = connection:commit(); if ok and commit_ok then if stmt:rowcount() > 0 then + module:log("info", "Upgrading database schema..."); local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); - local ok = stmt:execute(); + local ok, err = stmt:execute(); local commit_ok = connection:commit(); if ok and commit_ok then module:log("info", "Database table automatically upgraded"); + else + module:log("error", "Failed to upgrade database schema (%s), please see " + .."http://prosody.im/doc/mysql for help", + err or "unknown error"); end end repeat until not stmt:fetch(); - else - module:log("error", "Failed to upgrade database schema, please see http://prosody.im/doc/mysql for help"); end end + elseif params.driver ~= "SQLite3" then -- SQLite normally fails to prepare for existing table + module:log("warn", "Prosody was not able to automatically check/create the database table (%s), " + .."see http://prosody.im/doc/modules/mod_storage_sql#table_management for help.", + err or "unknown error"); end end -- cgit v1.2.3