[ejabberd] How to change mnesia table type by command line ?

Badlop badlop at gmail.com
Wed Dec 1 21:28:45 MSK 2010


2010/12/1 Manuel DE FERRAN <mdeferran at ubikod.com>:
> I'm trying to change disc_copies mnesia tables to ram_copies. But I'd like
> to do it with a script.

If I understood correctly, you want to do something like:
ejabberdctl mnesia_change_tabletype bytestream disc_only_copies

You can apply this patch to ejabberd 2.1.x (or to 2.1.5, or manually
to mod_admin_extra):

-------------------
--- a/src/ejabberd_admin.erl
+++ b/src/ejabberd_admin.erl
@@ -47,6 +47,7 @@
         install_fallback_mnesia/1,
         dump_to_textfile/1, dump_to_textfile/2,
         mnesia_change_nodename/4,
+        mnesia_change_tabletype/2,
         restore/1 % Still used by some modules
        ]).

@@ -173,6 +174,13 @@ commands() ->
                        args = [{oldnodename, string}, {newnodename, string},
                                {oldbackup, string}, {newbackup, string}],
                        result = {res, restuple}},
+
+     #ejabberd_commands{name = mnesia_change_tabletype, tags = [mnesia],
+                       desc = "Change the type of a mnesia table in
the local node",
+                       module = ?MODULE, function = mnesia_change_tabletype,
+                       args = [{table, string}, {type, string}],
+                       result = {res, rescode}},
+
      #ejabberd_commands{name = backup, tags = [mnesia],
                        desc = "Store the database to backup file",
                        module = ?MODULE, function = backup_mnesia,
@@ -582,3 +590,8 @@ mnesia_change_nodename(FromString, ToString,
Source, Target) ->
                {[Other], Acc}
        end,
     mnesia:traverse_backup(Source, Target, Convert, switched).
+
+mnesia_change_tabletype(TableS, TypeS) ->
+    {atomic, ok} = mnesia:change_table_copy_type(list_to_atom(TableS),
+                                                node(), list_to_atom(TypeS)),
+    ok.

-------------------


---
Badlop
ProcessOne


More information about the ejabberd mailing list