Mercurial > prosody-modules
comparison mod_migrate/mod_migrate.lua @ 4398:a16b689525d7
mod_migrate: Allow migrating data not attached to any user / nil user
Certain data more related to the server itself is stored with user = nil
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 26 Jan 2021 17:18:44 +0100 |
| parents | c9e1eee6a948 |
| children | f61564e11d3b |
comparison
equal
deleted
inserted
replaced
| 4397:6e0aa163298f | 4398:a16b689525d7 |
|---|---|
| 26 local target = assert(sm.load_driver(host, migrate_to)); | 26 local target = assert(sm.load_driver(host, migrate_to)); |
| 27 target = assert(target:open(source_store, store_type)); | 27 target = assert(target:open(source_store, store_type)); |
| 28 | 28 |
| 29 local function migrate_user(username) | 29 local function migrate_user(username) |
| 30 module:log("info", "Migrating %s data for %s", source_store, username); | 30 module:log("info", "Migrating %s data for %s", source_store, username); |
| 31 if username == "" then username = nil; end | |
| 31 local data, err = storage:get(username); | 32 local data, err = storage:get(username); |
| 32 if not data and err then | 33 if not data and err then |
| 33 module:log("error", "Could not read data: %s", err); | 34 module:log("error", "Could not read data: %s", err); |
| 34 else | 35 else |
| 35 local ok, err = target:set(username, data); | 36 local ok, err = target:set(username, data); |
| 40 end | 41 end |
| 41 | 42 |
| 42 if store_type == "archive" then | 43 if store_type == "archive" then |
| 43 function migrate_user(username) | 44 function migrate_user(username) |
| 44 module:log("info", "Migrating %s archive items for %s", source_store, username); | 45 module:log("info", "Migrating %s archive items for %s", source_store, username); |
| 46 if username == "" then username = nil; end | |
| 45 local count, errs = 0, 0; | 47 local count, errs = 0, 0; |
| 46 for id, item, when, with in storage:find(username) do | 48 for id, item, when, with in storage:find(username) do |
| 47 local ok, err = target:append(username, id, item, when, with); | 49 local ok, err = target:append(username, id, item, when, with); |
| 48 if ok then | 50 if ok then |
| 49 count = count + 1; | 51 count = count + 1; |
