aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-04-01 19:39:20 +0200
committerKim Alvefur <zash@zash.se>2017-04-01 19:39:20 +0200
commit29c30180ee535df52089db53287bdfa8b0c8e61b (patch)
treedbeac2bb0cefb030eab5dca2aa42d274c02f6d59
parent61d955084fb668b8310ed7e5ba66556b9577f193 (diff)
downloadprosody-29c30180ee535df52089db53287bdfa8b0c8e61b.tar.gz
prosody-29c30180ee535df52089db53287bdfa8b0c8e61b.zip
mod_storage_sql: Pass SQL engine as an argument to upgrade and table creator functions
-rw-r--r--plugins/mod_storage_sql.lua12
1 files changed, 6 insertions, 6 deletions
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