Software /
code /
prosody
Changeset
8034:149553feb04e
mod_storage_sql: Pass SQL engine as an argument to upgrade and table creator functions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 01 Apr 2017 19:39:20 +0200 |
parents | 8033:6c3cae9b96cb |
children | 8035:58d6c2ab3d16 |
files | plugins/mod_storage_sql.lua |
diffstat | 1 files changed, 6 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua Sat Apr 01 19:26:27 2017 +0200 +++ b/plugins/mod_storage_sql.lua Sat Apr 01 19:39:20 2017 +0200 @@ -423,7 +423,7 @@ --- Initialization -local function create_table(name) +local function create_table(engine, name) -- luacheck: ignore 431/engine local Table, Column, Index = sql.Table, sql.Column, sql.Index; local ProsodyTable = Table { @@ -458,7 +458,7 @@ end); end -local function upgrade_table(params, apply_changes) +local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine local changes = false; if params.driver == "MySQL" then local success,err = engine:transaction(function() @@ -540,13 +540,13 @@ engine = engines[sql.db2uri(params)]; if not engine then module:log("debug", "Creating new engine"); - engine = sql:create_engine(params, function (engine) + engine = sql:create_engine(params, function (engine) -- luacheck: ignore 431/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(); + create_table(engine); -- Check whether the table needs upgrading - if upgrade_table(params, false) then + if upgrade_table(engine, params, false) then module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); return false, "database upgrade needed"; end @@ -583,7 +583,7 @@ for _, params in pairs(uris) do print("Checking "..params.database.."..."); engine = sql:create_engine(params); - upgrade_table(params, true); + upgrade_table(engine, params, true); end print("All done!"); elseif command then