Comparison

tools/migration/prosody-migrator.lua @ 12168:33e856c65033

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
author Kim Alvefur <zash@zash.se>
date Sun, 09 Jan 2022 18:52:58 +0100
parent 12167:03f551510b1e
child 12387:05c250fa335a
comparison
equal deleted inserted replaced
12167:03f551510b1e 12168:33e856c65033
183 for id, item, when, with in iter do 183 for id, item, when, with in iter do
184 assert(destination:append(user, id, item, when, with)); 184 assert(destination:append(user, id, item, when, with));
185 end 185 end
186 end; 186 end;
187 } 187 }
188 migrate_once.pubsub = function(origin, destination, user, prefix, input_driver, output_driver)
189 if not user and prefix == "pubsub_" then return end
190 local data, err = origin:get(user);
191 assert(not err, err);
192 if not data then return end
193 assert(destination:set(user, data));
194 if prefix == "pubsub_" then user = nil end
195 for node in pairs(data) do
196 local pep_origin = assert(input_driver:open(prefix .. node, "archive"));
197 local pep_destination = assert(output_driver:open(prefix .. node, "archive"));
198 migrate_once.archive(pep_origin, pep_destination, user);
199 end
200 end
188 201
189 if options["keep-going"] then 202 if options["keep-going"] then
190 local xpcall = require "util.xpcall".xpcall; 203 local xpcall = require "util.xpcall".xpcall;
191 for t, f in pairs(migrate_once) do 204 for t, f in pairs(migrate_once) do
192 migrate_once[t] = function (origin, destination, user) 205 migrate_once[t] = function (origin, destination, user, ...)
193 local function log_err(err) 206 local function log_err(err)
194 if user then 207 if user then
195 log("error", "Error migrating data for user %q: %s", user, err); 208 log("error", "Error migrating data for user %q: %s", user, err);
196 else 209 else
197 log("error", "Error migrating data for host: %s", err); 210 log("error", "Error migrating data for host: %s", err);
198 end 211 end
199 log("debug", "%s", debug.traceback(nil, 2)); 212 log("debug", "%s", debug.traceback(nil, 2));
200 end 213 end
201 xpcall(f, log_err, origin, destination, user); 214 xpcall(f, log_err, origin, destination, user, ...);
202 end 215 end
203 end 216 end
204 end 217 end
205 218
206 local migration_runner = async.runner(function (job) 219 local migration_runner = async.runner(function (job)
216 for _, store in ipairs(stores) do 229 for _, store in ipairs(stores) do
217 local p, typ = store:match("()%-(%w+)$"); 230 local p, typ = store:match("()%-(%w+)$");
218 if typ then store = store:sub(1, p-1); else typ = "keyval"; end 231 if typ then store = store:sub(1, p-1); else typ = "keyval"; end
219 log("info", "Migrating host %s store %s (%s)", host, store, typ); 232 log("info", "Migrating host %s store %s (%s)", host, store, typ);
220 233
234 local migrate = assert(migrate_once[typ], "Unknown store type: "..typ);
235
236 local prefix = store .. "_";
237 if typ == "pubsub" then typ = "keyval"; end
238 if store == "pubsub_nodes" then prefix = "pubsub_"; end
239
221 local origin = assert(input_driver:open(store, typ)); 240 local origin = assert(input_driver:open(store, typ));
222 local destination = assert(output_driver:open(store, typ)); 241 local destination = assert(output_driver:open(store, typ));
223 242
224 local migrate = assert(migrate_once[typ], "Unknown store type: "..typ); 243 migrate(origin, destination, nil, prefix, input_driver, output_driver); -- host data
225
226 migrate(origin, destination, nil); -- host data
227 244
228 for user in users(origin, host) do 245 for user in users(origin, host) do
229 log("info", "Migrating user %s@%s store %s (%s)", user, host, store, typ); 246 log("info", "Migrating user %s@%s store %s (%s)", user, host, store, typ);
230 migrate(origin, destination, user); 247 migrate(origin, destination, user, prefix, input_driver, output_driver);
231 end 248 end
232 end 249 end
233 end 250 end
234 end, watchers); 251 end, watchers);
235 252