From b89b681cd2e5a96767d6503b55dba8df451b8073 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Nov 2016 07:30:39 +0100 Subject: mod_storage_sql: Use is_stanza() from util.stanza --- plugins/mod_storage_sql.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 4f46b3f6..b7ade340 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -7,10 +7,8 @@ local xml_parse = require "util.xml".parse; local uuid = require "util.uuid"; local resolve_relative_path = require "util.paths".resolve_relative_path; -local stanza_mt = require"util.stanza".stanza_mt; -local getmetatable = getmetatable; +local is_stanza = require"util.stanza".is_stanza; local t_concat = table.concat; -local function is_stanza(x) return getmetatable(x) == stanza_mt; end local noop = function() end local unpack = unpack -- cgit v1.2.3 From 011ee227bbe13347cb4e97d8ac2a65444ba4d57f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 29 Nov 2016 08:20:42 +0100 Subject: mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636) --- plugins/mod_storage_sql.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index b7ade340..fa241ed9 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -433,14 +433,22 @@ local function upgrade_table(params, apply_changes) return changes; end -local function normalize_params(params) - if params.driver == "SQLite3" then - if params.database ~= ":memory:" then - params.database = resolve_relative_path(prosody.paths.data or ".", params.database or "prosody.sqlite"); - end +local function normalize_database(driver, database) + if driver == "SQLite3" and database ~= ":memory:" then + return resolve_relative_path(prosody.paths.data or ".", database or "prosody.sqlite"); end - assert(params.driver and params.database, "Configuration error: Both the SQL driver and the database need to be specified"); - return params; + return database; +end + +local function normalize_params(params) + return { + driver = assert(params.driver, "Configuration error: Both the SQL driver and the database need to be specified"); + database = assert(normalize_database(params.driver, params.database), "Configuration error: Both the SQL driver and the database need to be specified"); + username = params.username; + password = params.password; + host = params.host; + params.port; + }; end function module.load() -- cgit v1.2.3 From 0176e27050a7e7c9b5aed0208002da509939c1d3 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 03:22:42 +0100 Subject: mod_storage_sql: Include missing parameter table key 'port' --- plugins/mod_storage_sql.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index fa241ed9..aef7ff8b 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -447,7 +447,7 @@ local function normalize_params(params) username = params.username; password = params.password; host = params.host; - params.port; + port = params.port; }; end -- cgit v1.2.3 From f1ce52f17d720b45d8fb6d804fa6808894829e07 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 10:02:01 +0100 Subject: mod_storage_sql: Don't say 'Unknown command' if no command was given (fixes attempt to concatenate nil) --- plugins/mod_storage_sql.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index aef7ff8b..1872ea34 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -504,6 +504,8 @@ function module.command(arg) upgrade_table(params, true); end print("All done!"); + elseif command then + print("Unknown command: "..command); else print("Unknown command: "..command); end -- cgit v1.2.3 From d0df7de3799bfd517ac06c2385a2dbecfe5ba34a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 10:02:26 +0100 Subject: mod_storage_sql: List available commands if no commands given (currenly only one available) --- plugins/mod_storage_sql.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 1872ea34..67a441b7 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -507,6 +507,7 @@ function module.command(arg) elseif command then print("Unknown command: "..command); else - print("Unknown command: "..command); + print("Available commands:"); + print("","upgrade - Perform database upgrade"); end end -- cgit v1.2.3 From 738528509c19ea443b4066e49b7a93fd2317b0ee Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 1 Dec 2016 10:02:57 +0100 Subject: mod_storage_sql: Normalize parameters for upgrade command --- plugins/mod_storage_sql.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 67a441b7..819846bb 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -484,7 +484,7 @@ function module.command(arg) -- We need to find every unique dburi in the config local uris = {}; for host in pairs(prosody.hosts) do - local params = config.get(host, "sql") or default_params; + local params = normalize_params(config.get(host, "sql") or default_params); uris[sql.db2uri(params)] = params; end print("We will check and upgrade the following databases:\n"); -- cgit v1.2.3