Software /
code /
prosody
Comparison
tools/migration/prosody-migrator.lua @ 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 |
parent | 12163:59b65cc6312f |
child | 12165:79a51a48bdaf |
comparison
equal
deleted
inserted
replaced
12163:59b65cc6312f | 12164:85f03b29ec72 |
---|---|
166 local function get_driver(host, conf) | 166 local function get_driver(host, conf) |
167 prepare_config(host, conf); | 167 prepare_config(host, conf); |
168 return assert(sm.load_driver(host, conf.type)); | 168 return assert(sm.load_driver(host, conf.type)); |
169 end | 169 end |
170 | 170 |
171 local migrate_once = { | |
172 keyval = function(origin, destination, user) | |
173 local data, err = origin:get(user); | |
174 assert(not err, err); | |
175 assert(destination:set(user, data)); | |
176 end; | |
177 archive = function(origin, destination, user) | |
178 local iter, err = origin:find(user); | |
179 assert(iter, err); | |
180 for id, item, when, with in iter do | |
181 assert(destination:append(user, id, item, when, with)); | |
182 end | |
183 end; | |
184 } | |
185 | |
171 local migration_runner = async.runner(function (job) | 186 local migration_runner = async.runner(function (job) |
172 for host, stores in pairs(job.input.hosts) do | 187 for host, stores in pairs(job.input.hosts) do |
173 prosody.hosts[host] = startup.make_host(host); | 188 prosody.hosts[host] = startup.make_host(host); |
174 sm.initialize_host(host); | 189 sm.initialize_host(host); |
175 um.initialize_host(host); | 190 um.initialize_host(host); |
184 log("info", "Migrating host %s store %s (%s)", host, store, typ); | 199 log("info", "Migrating host %s store %s (%s)", host, store, typ); |
185 | 200 |
186 local origin = assert(input_driver:open(store, typ)); | 201 local origin = assert(input_driver:open(store, typ)); |
187 local destination = assert(output_driver:open(store, typ)); | 202 local destination = assert(output_driver:open(store, typ)); |
188 | 203 |
204 local migrate = assert(migrate_once[typ], "Unknown store type: "..typ); | |
189 if typ == "keyval" then -- host data | 205 if typ == "keyval" then -- host data |
190 local data, err = origin:get(nil); | 206 migrate(origin, destination, nil); |
191 assert(not err, err); | |
192 assert(destination:set(nil, data)); | |
193 end | 207 end |
194 | 208 |
195 for user in users(origin, host) do | 209 for user in users(origin, host) do |
196 if typ == "keyval" then | 210 migrate(origin, destination, user); |
197 local data, err = origin:get(user); | |
198 assert(not err, err); | |
199 assert(destination:set(user, data)); | |
200 elseif typ == "archive" then | |
201 local iter, err = origin:find(user); | |
202 assert(iter, err); | |
203 for id, item, when, with in iter do | |
204 assert(destination:append(user, id, item, when, with)); | |
205 end | |
206 else | |
207 error("Don't know how to migrate data of type '"..typ.."'."); | |
208 end | |
209 end | 211 end |
210 end | 212 end |
211 end | 213 end |
212 end, watchers); | 214 end, watchers); |
213 | 215 |