aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-21 16:54:56 +0100
committerKim Alvefur <zash@zash.se>2016-02-21 16:54:56 +0100
commit2675b63e1b14a929277d2ad8bcf6f1ec17187de2 (patch)
tree44401c36441d4a2c7cd38aebe9b2466a64470a0f
parent9e960c96e70ead67889c4d6fbc91b0260340887d (diff)
parent7038a99a47f39fe87c192e75afadb3bb9463aca0 (diff)
downloadprosody-2675b63e1b14a929277d2ad8bcf6f1ec17187de2.tar.gz
prosody-2675b63e1b14a929277d2ad8bcf6f1ec17187de2.zip
Merge 0.10->trunk
-rw-r--r--plugins/mod_storage_sql.lua31
1 files changed, 19 insertions, 12 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 34fcacee..50d34a23 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -148,7 +148,8 @@ function map_store:get(username, key)
return result;
end
function map_store:set(username, key, data)
- return self:set_keys(username, { [key] = data or self.remove });
+ if data == nil then data = self.remove; end
+ return self:set_keys(username, { [key] = data });
end
function map_store:set_keys(username, keydatas)
local ok, result = engine:transaction(function()
@@ -448,19 +449,25 @@ end
function module.load()
if prosody.prosodyctl then return; end
+ local engines = module:shared("/*/sql/connections");
local params = normalize_params(module:get_option("sql", default_params));
- engine = sql:create_engine(params, function (engine)
- if module:get_option("sql_manage_tables", true) then
- -- Automatically create table, ignore failure (table probably already exists)
- -- FIXME: we should check in information_schema, etc.
- create_table();
- -- Check whether the table needs upgrading
- if upgrade_table(params, false) then
- module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name);
- return false, "database upgrade needed";
+ engine = engines[sql.db2uri(params)];
+ if not engine then
+ module:log("info", "Creating new engine");
+ engine = sql:create_engine(params, function (engine)
+ if module:get_option("sql_manage_tables", true) then
+ -- Automatically create table, ignore failure (table probably already exists)
+ -- FIXME: we should check in information_schema, etc.
+ create_table();
+ -- Check whether the table needs upgrading
+ if upgrade_table(params, false) then
+ module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name);
+ return false, "database upgrade needed";
+ end
end
- end
- end);
+ end);
+ engines[sql.db2uri(params)] = engine;
+ end
module:provides("storage", driver);
end