aboutsummaryrefslogtreecommitdiffstats
path: root/tools/migration
diff options
context:
space:
mode:
Diffstat (limited to 'tools/migration')
-rw-r--r--tools/migration/migrator/jabberd14.lua7
-rw-r--r--tools/migration/migrator/mtools.lua10
-rw-r--r--tools/migration/migrator/prosody_files.lua10
-rw-r--r--tools/migration/migrator/prosody_sql.lua12
-rw-r--r--tools/migration/prosody-migrator.lua28
5 files changed, 32 insertions, 35 deletions
diff --git a/tools/migration/migrator/jabberd14.lua b/tools/migration/migrator/jabberd14.lua
index 2f0b0b78..a4eef3f7 100644
--- a/tools/migration/migrator/jabberd14.lua
+++ b/tools/migration/migrator/jabberd14.lua
@@ -9,7 +9,6 @@ local ipairs = ipairs;
local coroutine = coroutine;
local print = print;
-module "jabberd14"
local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end
local function is_file(path) return lfs.attributes(path, "mode") == "file"; end
@@ -128,7 +127,7 @@ local function loop_over_hosts(path, cb)
end
end
-function reader(input)
+local function reader(input)
local path = clean_path(assert(input.path, "no input.path specified"));
assert(is_dir(path), "input.path is not a directory");
@@ -139,4 +138,6 @@ function reader(input)
end
end
-return _M;
+return {
+ reader = reader;
+};
diff --git a/tools/migration/migrator/mtools.lua b/tools/migration/migrator/mtools.lua
index e7b774bb..cfbfcce8 100644
--- a/tools/migration/migrator/mtools.lua
+++ b/tools/migration/migrator/mtools.lua
@@ -4,9 +4,8 @@ local print = print;
local t_insert = table.insert;
local t_sort = table.sort;
-module "mtools"
-function sorted(params)
+local function sorted(params)
local reader = params.reader; -- iterator to get items from
local sorter = params.sorter; -- sorting function
@@ -28,7 +27,7 @@ function sorted(params)
end
-function merged(reader, merger)
+local function merged(reader, merger)
local item1 = reader();
local merged = { item1 };
@@ -53,4 +52,7 @@ function merged(reader, merger)
end
-return _M;
+return {
+ sorted = sorted;
+ merged = merged;
+}
diff --git a/tools/migration/migrator/prosody_files.lua b/tools/migration/migrator/prosody_files.lua
index c9367d9c..4de09273 100644
--- a/tools/migration/migrator/prosody_files.lua
+++ b/tools/migration/migrator/prosody_files.lua
@@ -18,7 +18,6 @@ local error = error;
prosody = {};
local dm = require "util.datamanager"
-module "prosody_files"
local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end
local function is_file(path) return lfs.attributes(path, "mode") == "file"; end
@@ -88,7 +87,7 @@ local function decode_user(item)
return userdata;
end
-function reader(input)
+local function reader(input)
local path = clean_path(assert(input.path, "no input.path specified"));
assert(is_dir(path), "input.path is not a directory");
local iter = coroutine.wrap(function()handle_root_dir(path);end);
@@ -127,7 +126,7 @@ function reader(input)
end
end
-function writer(output)
+local function writer(output)
local path = clean_path(assert(output.path, "no output.path specified"));
assert(is_dir(path), "output.path is not a directory");
return function(item)
@@ -139,4 +138,7 @@ function writer(output)
end
end
-return _M;
+return {
+ reader = reader;
+ writer = writer;
+}
diff --git a/tools/migration/migrator/prosody_sql.lua b/tools/migration/migrator/prosody_sql.lua
index 27b5835e..0041ca9e 100644
--- a/tools/migration/migrator/prosody_sql.lua
+++ b/tools/migration/migrator/prosody_sql.lua
@@ -15,7 +15,6 @@ if not have_DBI then
error("LuaDBI (required for SQL support) was not found, please see http://prosody.im/doc/depends#luadbi", 0);
end
-module "prosody_sql"
local function create_table(connection, params)
local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);";
@@ -24,7 +23,7 @@ local function create_table(connection, params)
elseif params.driver == "MySQL" then
create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT");
end
-
+
local stmt = connection:prepare(create_sql);
if stmt then
local ok = stmt:execute();
@@ -110,7 +109,7 @@ local function decode_user(item)
return userdata;
end
-function reader(input)
+local function reader(input)
local dbh = assert(DBI.Connect(
assert(input.driver, "no input.driver specified"),
assert(input.database, "no input.database specified"),
@@ -154,7 +153,7 @@ function reader(input)
end;
end
-function writer(output, iter)
+local function writer(output, iter)
local dbh = assert(DBI.Connect(
assert(output.driver, "no output.driver specified"),
assert(output.database, "no output.database specified"),
@@ -197,4 +196,7 @@ function writer(output, iter)
end
-return _M;
+return {
+ reader = reader;
+ writer = writer;
+}
diff --git a/tools/migration/prosody-migrator.lua b/tools/migration/prosody-migrator.lua
index 7c933b88..6cff9f67 100644
--- a/tools/migration/prosody-migrator.lua
+++ b/tools/migration/prosody-migrator.lua
@@ -5,30 +5,29 @@ CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR");
-- Substitute ~ with path to home directory in paths
if CFG_CONFIGDIR then
- CFG_CONFIGDIR = CFG_CONFIGDIR:gsub("^~", os.getenv("HOME"));
+ CFG_CONFIGDIR = CFG_CONFIGDIR:gsub("^~", os.getenv("HOME"));
end
if CFG_SOURCEDIR then
- CFG_SOURCEDIR = CFG_SOURCEDIR:gsub("^~", os.getenv("HOME"));
+ CFG_SOURCEDIR = CFG_SOURCEDIR:gsub("^~", os.getenv("HOME"));
end
local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua";
-- Command-line parsing
local options = {};
-local handled_opts = 0;
-for i = 1, #arg do
+local i = 1;
+while arg[i] do
if arg[i]:sub(1,2) == "--" then
local opt, val = arg[i]:match("([%w-]+)=?(.*)");
if opt then
options[(opt:sub(3):gsub("%-", "_"))] = #val > 0 and val or true;
end
- handled_opts = i;
+ table.remove(arg, i);
else
- break;
+ i = i + 1;
end
end
-table.remove(arg, handled_opts);
if CFG_SOURCEDIR then
package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
@@ -40,24 +39,15 @@ end
local envloadfile = require "util.envload".envloadfile;
--- Load config file
-local function loadfilein(file, env)
- if loadin then
- return loadin(env, io.open(file):read("*a"));
- else
- return envloadfile(file, env);
- end
-end
-
local config_file = options.config or default_config;
local from_store = arg[1] or "input";
local to_store = arg[2] or "output";
config = {};
local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end });
-local config_chunk, err = loadfilein(config_file, config_env);
+local config_chunk, err = envloadfile(config_file, config_env);
if not config_chunk then
- print("There was an error loading the config file, check the file exists");
+ print("There was an error loading the config file, check that the file exists");
print("and that the syntax is correct:");
print("", err);
os.exit(1);
@@ -115,7 +105,7 @@ if have_err then
print("");
os.exit(1);
end
-
+
local itype = config[from_store].type;
local otype = config[to_store].type;
local reader = require("migrator."..itype).reader(config[from_store]);