[ejabberd] Ejabberd Mnesia work

Badlop badlop at safe-mail.net
Wed Jan 26 12:50:22 MSK 2005

Oleg V. Motienko escribió:
> Martyn Baker wrote:
>> Does anyone out there have any tools for manipulating the mnesia 
>> tables directly ? I wanted to amend the entries for the JID's and 
>> change the domain name for all exisitng 110 users and their rosters 
>> without having to recreate them all.
> The same situation for me. Maybe anybody already made a tool for 
> changing domain in ejabberd?
> If yes, publish it, please.

Ermine wrote a tool some time ago and passed it to me. I've not tried it 
yet, so there're no instructions (this is a call for help ;). You can 
find Ermine in ejabberd chatroom at ejabberd at conference.jabber.ru



change_node_name(From, To, Source, Target) ->
     Switch =
         fun(Node) when Node == From -> To;
            (Node) when Node == To -> throw({error, already_exists});
                                             (Node) -> Node
     Convert =
         fun({schema, db_nodes, Nodes}, Acc) ->
                 {[{schema, db_nodes, lists:map(Switch,Nodes)}], Acc};
            ({schema, version, Version}, Acc) ->
                 {[{schema, version, Version}], Acc};
            ({schema, cookie, Cookie}, Acc) ->
                 {[{schema, cookie, Cookie}], Acc};
            ({schema, Tab, CreateList}, Acc) ->
                 Keys = [ram_copies, disc_copies, disc_only_copies],
                 OptSwitch =
                     fun({Key, Val}) ->
                             case lists:member(Key, Keys) of
                                 true -> {Key, lists:map(Switch, Val)};
                                 false-> {Key, Val}
                 {[{schema, Tab, lists:map(OptSwitch, CreateList)}], Acc};
            (Other, Acc) ->
                 {[Other], Acc}
     mnesia:traverse_backup(Source, Target, Convert, switched).

More information about the ejabberd mailing list