From 29c30180ee535df52089db53287bdfa8b0c8e61b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 1 Apr 2017 19:39:20 +0200 Subject: mod_storage_sql: Pass SQL engine as an argument to upgrade and table creator functions --- plugins/mod_storage_sql.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 40a59911..b6b71138 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -423,7 +423,7 @@ end --- 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 @@ local function create_table(name) 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 @@ function module.load() 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 @@ function module.command(arg) 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 -- cgit v1.2.3