aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql2.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2015-07-07 17:41:09 +0100
committerMatthew Wild <mwild1@gmail.com>2015-07-07 17:41:09 +0100
commit68fa7831dada4d821ddff964723c376f287d4ed5 (patch)
tree168350a011c33ef0f26561bf893c284e97abbc1d /plugins/mod_storage_sql2.lua
parent86822ee5e4dadd72ed000669dcbecebdf57f87cb (diff)
downloadprosody-68fa7831dada4d821ddff964723c376f287d4ed5.tar.gz
prosody-68fa7831dada4d821ddff964723c376f287d4ed5.zip
mod_storage_sql2: Add prosodyctl command to upgrade tables from the command-line
Diffstat (limited to 'plugins/mod_storage_sql2.lua')
-rw-r--r--plugins/mod_storage_sql2.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql2.lua b/plugins/mod_storage_sql2.lua
index 59c50b5a..b040cb05 100644
--- a/plugins/mod_storage_sql2.lua
+++ b/plugins/mod_storage_sql2.lua
@@ -405,3 +405,36 @@ function module.load()
module:provides("storage", driver);
end
+
+function module.command(arg)
+ local config = require "core.configmanager";
+ local prosodyctl = require "util.prosodyctl";
+ local command = table.remove(arg, 1);
+ if command == "upgrade" then
+ -- 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;
+ uris[sql.db2uri(params)] = params;
+ end
+ print("We will check and upgrade the following databases:\n");
+ for _, params in pairs(uris) do
+ print("", "["..params.driver.."] "..params.database..(params.host and " on "..params.host or ""));
+ end
+ print("");
+ print("Ensure you have working backups of the above databases before continuing! ");
+ if not prosodyctl.show_yesno("Continue with the database upgrade? [yN]") then
+ print("Ok, no upgrade. But you do have backups, don't you? ...don't you?? :-)");
+ return;
+ end
+ -- Upgrade each one
+ for _, params in pairs(uris) do
+ print("Checking "..params.database.."...");
+ engine = sql:create_engine(params);
+ upgrade_table(params, true);
+ end
+ print("All done!");
+ else
+ print("Unknown command: "..command);
+ end
+end