aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-21 14:53:19 +0100
committerKim Alvefur <zash@zash.se>2016-02-21 14:53:19 +0100
commit7038a99a47f39fe87c192e75afadb3bb9463aca0 (patch)
tree9489ad813912e267c7bcfe361df46e862f29f5bb /plugins
parent0ca52545bc71caa5c805d6e4864d442442ad07a2 (diff)
downloadprosody-7038a99a47f39fe87c192e75afadb3bb9463aca0.tar.gz
prosody-7038a99a47f39fe87c192e75afadb3bb9463aca0.zip
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua28
1 files changed, 17 insertions, 11 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 6efa676c..50d34a23 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -449,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