Comparison

plugins/mod_storage_sql2.lua @ 6756:2e75b94e3a1e

mod_storage_sql2: Add prosodyctl command to upgrade tables from the command-line
author Matthew Wild <mwild1@gmail.com>
date Tue, 07 Jul 2015 17:41:09 +0100
parent 6755:b80202ad47e8
child 6757:fc9c1a566a19
comparison
equal deleted inserted replaced
6755:b80202ad47e8 6756:2e75b94e3a1e
403 end 403 end
404 end); 404 end);
405 405
406 module:provides("storage", driver); 406 module:provides("storage", driver);
407 end 407 end
408
409 function module.command(arg)
410 local config = require "core.configmanager";
411 local prosodyctl = require "util.prosodyctl";
412 local command = table.remove(arg, 1);
413 if command == "upgrade" then
414 -- We need to find every unique dburi in the config
415 local uris = {};
416 for host in pairs(prosody.hosts) do
417 local params = config.get(host, "sql") or default_params;
418 uris[sql.db2uri(params)] = params;
419 end
420 print("We will check and upgrade the following databases:\n");
421 for _, params in pairs(uris) do
422 print("", "["..params.driver.."] "..params.database..(params.host and " on "..params.host or ""));
423 end
424 print("");
425 print("Ensure you have working backups of the above databases before continuing! ");
426 if not prosodyctl.show_yesno("Continue with the database upgrade? [yN]") then
427 print("Ok, no upgrade. But you do have backups, don't you? ...don't you?? :-)");
428 return;
429 end
430 -- Upgrade each one
431 for _, params in pairs(uris) do
432 print("Checking "..params.database.."...");
433 engine = sql:create_engine(params);
434 upgrade_table(params, true);
435 end
436 print("All done!");
437 else
438 print("Unknown command: "..command);
439 end
440 end