Apply improvement from 29462f005 to delete/2, and fix delete/3 (#3564)

This commit is contained in:
Badlop 2021-05-13 13:38:40 +02:00
parent ee3796b925
commit 20b4deffe3
2 changed files with 11 additions and 6 deletions

View File

@ -317,7 +317,8 @@ get_commands_spec() ->
#ejabberd_commands{name = export2sql, tags = [mnesia],
desc = "Export virtual host information from Mnesia tables to SQL file",
longdesc = "Configure the modules to use SQL, then call this command.",
longdesc = "Configure the modules to use SQL, then call this command. "
"After correct export, check 'delete_mnesia' too.",
module = ejd2sql, function = export,
args_desc = ["Vhost", "Full path to the destination SQL file"],
args_example = ["example.com", "/var/lib/ejabberd/example.com.sql"],

View File

@ -104,12 +104,17 @@ delete(Server) ->
delete(Server, Module)
end, Modules).
delete(Server, Module) ->
delete(Server, Module1) ->
LServer = jid:nameprep(iolist_to_binary(Server)),
Module = case Module1 of
mod_pubsub -> pubsub_db;
_ -> Module1
end,
SQLMod = gen_mod:db_mod(sql, Module),
lists:foreach(
fun({Table, ConvertFun}) ->
delete(LServer, Table, ConvertFun)
end, Module:export(Server)).
end, SQLMod:export(Server)).
import(Server, Dir, ToType) ->
lists:foreach(
@ -192,7 +197,7 @@ output(_LServer, Table, Fd, SQLs) ->
delete(LServer, Table, ConvertFun) ->
F = fun () ->
mnesia:write_lock_table(Table),
{_N, SQLs} =
{_N, _SQLs} =
mnesia:foldl(
fun(R, Acc) ->
case ConvertFun(LServer, R) of
@ -203,8 +208,7 @@ delete(LServer, Table, ConvertFun) ->
Acc
end
end,
{0, []}, Table),
delete(LServer, Table, SQLs)
{0, []}, Table)
end,
mnesia:transaction(F).