Software /
code /
prosody
Changeset
12164:85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 09 Jan 2022 15:50:21 +0100 |
parents | 12163:59b65cc6312f |
children | 12165:79a51a48bdaf |
files | tools/migration/prosody-migrator.lua |
diffstat | 1 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/migration/prosody-migrator.lua Sun Jan 09 16:15:21 2022 +0100 +++ b/tools/migration/prosody-migrator.lua Sun Jan 09 15:50:21 2022 +0100 @@ -168,6 +168,21 @@ 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 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