Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 7170:fb37aece3252
mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 21 Feb 2016 14:53:19 +0100 |
parent | 7169:d00d8cfcc9a8 |
child | 7173:d8c060615aa1 |
comparison
equal
deleted
inserted
replaced
7169:d00d8cfcc9a8 | 7170:fb37aece3252 |
---|---|
447 return params; | 447 return params; |
448 end | 448 end |
449 | 449 |
450 function module.load() | 450 function module.load() |
451 if prosody.prosodyctl then return; end | 451 if prosody.prosodyctl then return; end |
452 local engines = module:shared("/*/sql/connections"); | |
452 local params = normalize_params(module:get_option("sql", default_params)); | 453 local params = normalize_params(module:get_option("sql", default_params)); |
453 engine = sql:create_engine(params, function (engine) | 454 engine = engines[sql.db2uri(params)]; |
454 if module:get_option("sql_manage_tables", true) then | 455 if not engine then |
455 -- Automatically create table, ignore failure (table probably already exists) | 456 module:log("info", "Creating new engine"); |
456 -- FIXME: we should check in information_schema, etc. | 457 engine = sql:create_engine(params, function (engine) |
457 create_table(); | 458 if module:get_option("sql_manage_tables", true) then |
458 -- Check whether the table needs upgrading | 459 -- Automatically create table, ignore failure (table probably already exists) |
459 if upgrade_table(params, false) then | 460 -- FIXME: we should check in information_schema, etc. |
460 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); | 461 create_table(); |
461 return false, "database upgrade needed"; | 462 -- Check whether the table needs upgrading |
462 end | 463 if upgrade_table(params, false) then |
463 end | 464 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); |
464 end); | 465 return false, "database upgrade needed"; |
466 end | |
467 end | |
468 end); | |
469 engines[sql.db2uri(params)] = engine; | |
470 end | |
465 | 471 |
466 module:provides("storage", driver); | 472 module:provides("storage", driver); |
467 end | 473 end |
468 | 474 |
469 function module.command(arg) | 475 function module.command(arg) |