mirror of
https://github.com/bjc/prosody.git
synced 2025-04-06 22:57:38 +03:00
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
This commit is contained in:
parent
1da9cde6ae
commit
c9d425731d
1 changed files with 17 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue