# HG changeset patch # User Kim Alvefur # Date 1641750778 -3600 # Node ID 33e856c6503373cd788a782088cef7ac3f87d8ba # Parent 03f551510b1e191ab09e24aab2c9980cbe850552 migrator: Support pubsub and pep as a special-case This sorta overloads the type suffix but PEP is used for enough stuff to justify this hack diff -r 03f551510b1e -r 33e856c65033 tools/migration/migrator.cfg.lua --- a/tools/migration/migrator.cfg.lua Sun Jan 09 16:35:43 2022 +0100 +++ b/tools/migration/migrator.cfg.lua Sun Jan 09 18:52:58 2022 +0100 @@ -10,10 +10,8 @@ "privacy", "archive-archive", "offline-archive", - "pubsub_nodes", - -- "pubsub_*-archive", - "pep", - -- "pep_*-archive", + "pubsub_nodes-pubsub", + "pep-pubsub", } local muc = { "persistent", diff -r 03f551510b1e -r 33e856c65033 tools/migration/prosody-migrator.lua --- a/tools/migration/prosody-migrator.lua Sun Jan 09 16:35:43 2022 +0100 +++ b/tools/migration/prosody-migrator.lua Sun Jan 09 18:52:58 2022 +0100 @@ -185,11 +185,24 @@ end end; } +migrate_once.pubsub = function(origin, destination, user, prefix, input_driver, output_driver) + if not user and prefix == "pubsub_" then return end + local data, err = origin:get(user); + assert(not err, err); + if not data then return end + assert(destination:set(user, data)); + if prefix == "pubsub_" then user = nil end + for node in pairs(data) do + local pep_origin = assert(input_driver:open(prefix .. node, "archive")); + local pep_destination = assert(output_driver:open(prefix .. node, "archive")); + migrate_once.archive(pep_origin, pep_destination, user); + end +end if options["keep-going"] then local xpcall = require "util.xpcall".xpcall; for t, f in pairs(migrate_once) do - migrate_once[t] = function (origin, destination, user) + migrate_once[t] = function (origin, destination, user, ...) local function log_err(err) if user then log("error", "Error migrating data for user %q: %s", user, err); @@ -198,7 +211,7 @@ end log("debug", "%s", debug.traceback(nil, 2)); end - xpcall(f, log_err, origin, destination, user); + xpcall(f, log_err, origin, destination, user, ...); end end end @@ -218,16 +231,20 @@ if typ then store = store:sub(1, p-1); else typ = "keyval"; end log("info", "Migrating host %s store %s (%s)", host, store, typ); + local migrate = assert(migrate_once[typ], "Unknown store type: "..typ); + + local prefix = store .. "_"; + if typ == "pubsub" then typ = "keyval"; end + if store == "pubsub_nodes" then prefix = "pubsub_"; end + 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); - - migrate(origin, destination, nil); -- host data + migrate(origin, destination, nil, prefix, input_driver, output_driver); -- host data for user in users(origin, host) do log("info", "Migrating user %s@%s store %s (%s)", user, host, store, typ); - migrate(origin, destination, user); + migrate(origin, destination, user, prefix, input_driver, output_driver); end end end