aboutsummaryrefslogtreecommitdiffstats
path: root/tools/migration/prosody-migrator.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-01-09 15:50:21 +0100
committerKim Alvefur <zash@zash.se>2022-01-09 15:50:21 +0100
commite9b2be9e444c35de0121e088e5fe857aea8397ef (patch)
tree7e699f10acd44136963d1e7fcb0b25dcc8c85616 /tools/migration/prosody-migrator.lua
parent25a9fd3fdd3b9889469024f0413cd64323661fa3 (diff)
downloadprosody-e9b2be9e444c35de0121e088e5fe857aea8397ef.tar.gz
prosody-e9b2be9e444c35de0121e088e5fe857aea8397ef.zip
migrator: Refactor out individual item migrator for code deduplication
Diffstat (limited to 'tools/migration/prosody-migrator.lua')
-rw-r--r--tools/migration/prosody-migrator.lua34
1 files changed, 18 insertions, 16 deletions
diff --git a/tools/migration/prosody-migrator.lua b/tools/migration/prosody-migrator.lua
index 905f92fb..bb8c8fdf 100644
--- a/tools/migration/prosody-migrator.lua
+++ b/tools/migration/prosody-migrator.lua
@@ -168,6 +168,21 @@ local function get_driver(host, conf)
return assert(sm.load_driver(host, conf.type));
end
+local migrate_once = {
+ keyval = function(origin, destination, user)
+ local data, err = origin:get(user);
+ assert(not err, err);
+ assert(destination:set(user, data));
+ end;
+ archive = function(origin, destination, user)
+ local iter, err = origin:find(user);
+ assert(iter, err);
+ for id, item, when, with in iter do
+ assert(destination:append(user, id, item, when, with));
+ end
+ end;
+}
+
local migration_runner = async.runner(function (job)
for host, stores in pairs(job.input.hosts) do
prosody.hosts[host] = startup.make_host(host);
@@ -186,26 +201,13 @@ local migration_runner = async.runner(function (job)
local origin = assert(input_driver:open(store, typ));
local destination = assert(output_driver:open(store, typ));
+ local migrate = assert(migrate_once[typ], "Unknown store type: "..typ);
if typ == "keyval" then -- host data
- local data, err = origin:get(nil);
- assert(not err, err);
- assert(destination:set(nil, data));
+ migrate(origin, destination, nil);
end
for user in users(origin, host) do
- if typ == "keyval" then
- local data, err = origin:get(user);
- assert(not err, err);
- assert(destination:set(user, data));
- elseif typ == "archive" then
- local iter, err = origin:find(user);
- assert(iter, err);
- for id, item, when, with in iter do
- assert(destination:append(user, id, item, when, with));
- end
- else
- error("Don't know how to migrate data of type '"..typ.."'.");
- end
+ migrate(origin, destination, user);
end
end
end