mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
New command delete_mnesia deletes all tables that can be exported
This commit is contained in:
parent
0112135096
commit
107569a17d
@ -196,6 +196,10 @@ get_commands_spec() ->
|
||||
desc = "Export all tables as SQL queries to a file",
|
||||
module = ejd2odbc, function = export,
|
||||
args = [{host, string}, {file, string}], result = {res, rescode}},
|
||||
#ejabberd_commands{name = delete_mnesia, tags = [mnesia, odbc],
|
||||
desc = "Export all tables as SQL queries to a file",
|
||||
module = ejd2odbc, function = delete,
|
||||
args = [{host, string}], result = {res, rescode}},
|
||||
#ejabberd_commands{name = convert_to_scram, tags = [odbc],
|
||||
desc = "Convert the passwords in 'users' ODBC table to SCRAM",
|
||||
module = ejabberd_auth_odbc, function = convert_to_scram,
|
||||
|
@ -30,7 +30,7 @@
|
||||
-include("logger.hrl").
|
||||
|
||||
-export([export/2, export/3, import_file/2, import/2,
|
||||
import/3]).
|
||||
import/3, delete/1]).
|
||||
|
||||
-define(MAX_RECORDS_PER_TRANSACTION, 100).
|
||||
|
||||
@ -80,6 +80,20 @@ export(Server, Output, Module) ->
|
||||
end, Module:export(Server)),
|
||||
close_output(Output, IO).
|
||||
|
||||
delete(Server) ->
|
||||
Modules = modules(),
|
||||
lists:foreach(
|
||||
fun(Module) ->
|
||||
delete(Server, Module)
|
||||
end, Modules).
|
||||
|
||||
delete(Server, Module) ->
|
||||
LServer = jid:nameprep(iolist_to_binary(Server)),
|
||||
lists:foreach(
|
||||
fun({Table, ConvertFun}) ->
|
||||
delete(LServer, Table, ConvertFun)
|
||||
end, Module:export(Server)).
|
||||
|
||||
import_file(Server, FileName) when is_binary(FileName) ->
|
||||
import(Server, binary_to_list(FileName));
|
||||
import_file(Server, FileName) ->
|
||||
@ -160,6 +174,25 @@ output(_LServer, Table, Fd, SQLs) ->
|
||||
file:write(Fd, ["-- \n-- Mnesia table: ", atom_to_list(Table),
|
||||
"\n--\n", SQLs]).
|
||||
|
||||
delete(LServer, Table, ConvertFun) ->
|
||||
F = fun () ->
|
||||
mnesia:write_lock_table(Table),
|
||||
{_N, SQLs} =
|
||||
mnesia:foldl(
|
||||
fun(R, {N, SQLs} = Acc) ->
|
||||
case ConvertFun(LServer, R) of
|
||||
[] ->
|
||||
Acc;
|
||||
_SQL ->
|
||||
mnesia:delete_object(R),
|
||||
Acc
|
||||
end
|
||||
end,
|
||||
{0, []}, Table),
|
||||
delete(LServer, Table, SQLs)
|
||||
end,
|
||||
mnesia:transaction(F).
|
||||
|
||||
import(LServer, SelectQuery, IO, ConvertFun, Opts) ->
|
||||
F = case proplists:get_bool(fast, Opts) of
|
||||
true ->
|
||||
|
Loading…
Reference in New Issue
Block a user