]> granicus.if.org Git - ejabberd/commitdiff
Improve handling of mnesia schema
authorChristophe Romain <christophe.romain@process-one.net>
Wed, 30 Nov 2016 10:09:17 +0000 (11:09 +0100)
committerChristophe Romain <christophe.romain@process-one.net>
Wed, 30 Nov 2016 10:09:17 +0000 (11:09 +0100)
41 files changed:
src/acl.erl
src/ejabberd_auth_anonymous.erl
src/ejabberd_auth_mnesia.erl
src/ejabberd_commands.erl
src/ejabberd_config.erl
src/ejabberd_local.erl
src/ejabberd_mnesia.erl [new file with mode: 0644]
src/ejabberd_oauth_mnesia.erl
src/ejabberd_router.erl
src/ejabberd_router_multicast.erl
src/ejabberd_s2s.erl
src/ejabberd_sm_mnesia.erl
src/ejabberd_sql_sup.erl
src/mod_announce_mnesia.erl
src/mod_bosh.erl
src/mod_caps_mnesia.erl
src/mod_carboncopy_mnesia.erl
src/mod_http_bind.erl
src/mod_irc_mnesia.erl
src/mod_last_mnesia.erl
src/mod_mam_mnesia.erl
src/mod_muc.erl
src/mod_muc_mnesia.erl
src/mod_multicast.erl
src/mod_offline_mnesia.erl
src/mod_privacy_mnesia.erl
src/mod_private_mnesia.erl
src/mod_proxy65_sm.erl
src/mod_pubsub.erl
src/mod_register.erl
src/mod_roster_mnesia.erl
src/mod_shared_roster_mnesia.erl
src/mod_sip_registrar.erl
src/mod_vcard_mnesia.erl
src/mod_vcard_xupdate_mnesia.erl
src/node_flat.erl
src/nodetree_tree.erl
src/pubsub_index.erl
src/pubsub_migrate.erl
src/pubsub_subscription.erl
src/shaper.erl

index 595228ee9fe88ad35bbbfd1abdb988f65f45f765..e00aaa5d304650079eb34f64996032c4624db2d5 100644 (file)
 -export_type([acl/0]).
 
 start() ->
-    mnesia:create_table(acl,
+    ejabberd_mnesia:create(?MODULE, acl,
                        [{ram_copies, [node()]}, {type, bag},
                          {local_content, true},
                         {attributes, record_info(fields, acl)}]),
-    mnesia:create_table(access,
+    ejabberd_mnesia:create(?MODULE, access,
                         [{ram_copies, [node()]},
                          {local_content, true},
                         {attributes, record_info(fields, access)}]),
index c84321ad9fd17853c2bcb6777a9d53cbb50de284..e0c4d471f0aaa42042cf3b86c8bae618c76fdb65 100644 (file)
@@ -59,7 +59,7 @@
 
 start(Host) ->
     %% TODO: Check cluster mode
-    mnesia:create_table(anonymous, [{ram_copies, [node()]},
+    ejabberd_mnesia:create(?MODULE, anonymous, [{ram_copies, [node()]},
                                    {type, bag},
                                    {attributes, record_info(fields, anonymous)}]),
     %% The hooks are needed to add / remove users from the anonymous tables
index dee3774db9a174384d7e13e5b8984e8167715d26..eac19f02460597e83ec76ba90fd11f9f1a2ca553 100644 (file)
@@ -66,10 +66,10 @@ start(Host) ->
     ok.
 
 init_db() ->
-    mnesia:create_table(passwd,
+    ejabberd_mnesia:create(?MODULE, passwd,
                        [{disc_copies, [node()]},
                         {attributes, record_info(fields, passwd)}]),
-    mnesia:create_table(reg_users_counter,
+    ejabberd_mnesia:create(?MODULE, reg_users_counter,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, reg_users_counter)}]).
 
index 6172b18ed62e5f3fa41769874c6d6f4cdf988174..223163a2b4b1e65ab18047e5ad0b218748b7c411 100644 (file)
@@ -281,7 +281,7 @@ init() ->
                               record_info(fields, ejabberd_commands))
     catch exit:{aborted, {no_exists, _}} -> ok
     end,
-    mnesia:create_table(ejabberd_commands,
+    ejabberd_mnesia:create(?MODULE, ejabberd_commands,
                         [{ram_copies, [node()]},
                          {local_content, true},
                          {attributes, record_info(fields, ejabberd_commands)},
index af26767f8cae8ea7f1a8edf8ef38128e64fe7bd4..e930e36b165541909eb06078df25b81b1eafef0b 100644 (file)
@@ -104,7 +104,7 @@ mnesia_init() ->
         _ ->
             ok
     end,
-    mnesia:create_table(local_config,
+    ejabberd_mnesia:create(?MODULE, local_config,
                        [{ram_copies, [node()]},
                         {local_content, true},
                         {attributes, record_info(fields, local_config)}]),
@@ -1300,7 +1300,7 @@ convert_table_to_binary(Tab, Fields, Type, DetectFun, ConvertFun) ->
             ?INFO_MSG("Converting '~s' table from strings to binaries.", [Tab]),
             TmpTab = list_to_atom(atom_to_list(Tab) ++ "_tmp_table"),
             catch mnesia:delete_table(TmpTab),
-            case mnesia:create_table(TmpTab,
+            case ejabberd_mnesia:create(?MODULE, TmpTab,
                                      [{disc_only_copies, [node()]},
                                       {type, Type},
                                       {local_content, true},
index 3406192f7438e6c1f054c1e09714599c94b50448..a5ee6a2428123ba00185c3ccb294a5833869e6e8 100644 (file)
@@ -205,7 +205,7 @@ init([]) ->
                  ?MYHOSTS),
     catch ets:new(?IQTABLE, [named_table, public]),
     update_table(),
-    mnesia:create_table(iq_response,
+    ejabberd_mnesia:create(?MODULE, iq_response,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, iq_response)}]),
     mnesia:add_table_copy(iq_response, node(), ram_copies),
diff --git a/src/ejabberd_mnesia.erl b/src/ejabberd_mnesia.erl
new file mode 100644 (file)
index 0000000..f244d51
--- /dev/null
@@ -0,0 +1,169 @@
+%%%----------------------------------------------------------------------
+%%% File    : mnesia_mnesia.erl
+%%% Author  : Christophe Romain <christophe.romain@process-one.net>
+%%% Purpose : Handle configurable mnesia schema
+%%% Created : 17 Nov 2016 by Christophe Romain <christophe.romain@process-one.net>
+%%%
+%%%
+%%% ejabberd, Copyright (C) 2002-2016   ProcessOne
+%%%
+%%% This program is free software; you can redistribute it and/or
+%%% modify it under the terms of the GNU General Public License as
+%%% published by the Free Software Foundation; either version 2 of the
+%%% License, or (at your option) any later version.
+%%%
+%%% This program is distributed in the hope that it will be useful,
+%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%%% General Public License for more details.
+%%%
+%%% You should have received a copy of the GNU General Public License along
+%%% with this program; if not, write to the Free Software Foundation, Inc.,
+%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+%%%
+%%%----------------------------------------------------------------------
+
+%%% This module should be used everywhere ejabberd creates a mnesia table
+%%% to make the schema customizable without code change
+%%% Just apply this change in ejabberd modules
+%%% s/ejabberd_mnesia:create(?MODULE, /ejabberd_mnesia:create(?MODULE, /
+
+-module(ejabberd_mnesia).
+-author('christophe.romain@process-one.net').
+-export([create/3, reset/2, update/2]).
+
+-define(STORAGE_TYPES, [disc_copies, disc_only_copies, ram_copies]).
+-define(NEED_RESET, [local_content, type]).
+
+create(Module, Name, TabDef) ->
+    Schema = schema(Module, Name, TabDef),
+    {attributes, Attrs} = lists:keyfind(attributes, 1, Schema),
+    case catch mnesia:table_info(Name, attributes) of
+       {'EXIT', _} ->
+           ejabberd_mnesia:create(?MODULE, Name, Schema);
+       Attrs ->
+           case need_reset(TabDef, Schema) of
+               true -> reset(Name, Schema);
+               false -> update(Name, Schema)
+           end;
+       OldAttrs ->
+           Fun = case lists:member({transform,1}, Module:module_info(exports)) of
+               true -> fun(Old) -> Module:transform(Old) end;
+               false -> fun(Old) -> transform(OldAttrs, Attrs, Old) end
+           end,
+           mnesia:transform_table(Name, Fun, Attrs)
+    end.
+
+reset(Name, TabDef) ->
+    mnesia:delete_table(Name),
+    ejabberd_mnesia:create(?MODULE, Name, TabDef).
+
+update(Name, TabDef) ->
+    Storage = mnesia:table_info(Name, storage_type),
+    NewStorage = lists:foldl(
+                  fun({Key, _}, Acc) ->
+                          case lists:member(Key, ?STORAGE_TYPES) of
+                              true -> Key;
+                              false -> Acc
+                          end
+                  end, Storage, TabDef),
+    R1 = if Storage=/=NewStorage ->
+           mnesia:change_table_copy_type(Name, node(), NewStorage);
+       true ->
+           {atomic, ok}
+    end,
+    Indexes = mnesia:table_info(Name, index),
+    NewIndexes = proplists:get_value(index, TabDef, []),
+    [mnesia:del_table_index(Name, Attr)
+     || Attr <- Indexes--NewIndexes],
+    R2 = [mnesia:add_table_index(Name, Attr)
+         || Attr <- NewIndexes--Indexes],
+    lists:foldl(
+      fun({atomic, ok}, Acc) -> Acc;
+        (Error, _Acc) -> Error
+      end, {atomic, ok}, [R1|R2]).
+
+%
+% utilities
+%
+
+schema(Module, Name, TabDef) ->
+    case parse(Module) of
+       {ok, CustomDefs} ->
+           case lists:keyfind(Name, 1, CustomDefs) of
+               {Name, CustomDef} -> merge(TabDef, CustomDef);
+               _ -> TabDef
+           end;
+       _ ->
+           TabDef
+    end.
+
+merge(TabDef, CustomDef) ->
+    {CustomKeys, _} = lists:unzip(CustomDef),
+    CleanDef = lists:foldl(
+               fun(Elem, Acc) ->
+                   case lists:member(Elem, ?STORAGE_TYPES) of
+                       true ->
+                           lists:foldl(
+                             fun(Key, CleanAcc) ->
+                                     lists:keydelete(Key, 1, CleanAcc)
+                             end, Acc, ?STORAGE_TYPES);
+                       false ->
+                           Acc
+                   end
+               end, TabDef, CustomKeys),
+    lists:ukeymerge(1,
+                  lists:ukeysort(1, CustomDef),
+                  lists:ukeysort(1, CleanDef)).
+
+parse(Module) ->
+    Path = case os:getenv("EJABBERD_SCHEMA_PATH") of
+               false ->
+                   case code:priv_dir(ejabberd) of
+                       {error, _} -> "schema";  % $SPOOL_DIR/schema
+                       Priv -> filename:join(Priv, "schema")
+                   end;
+               CustomDir ->
+                   CustomDir
+           end,
+    File = filename:join(Path, atom_to_list(Module)++".mnesia"),
+    case file:consult(File) of
+       {ok, Terms} -> parse(Terms, []);
+       Error -> Error
+    end.
+
+parse([], Acc) ->
+    {ok, lists:reverse(Acc)};
+parse([{Name, Storage, TabDef}|Tail], Acc)
+  when is_atom(Name),
+       is_atom(Storage),
+       is_list(TabDef) ->
+    NewDef = case lists:member(Storage, ?STORAGE_TYPES) of
+       true -> [{Storage, [node()]} | TabDef];
+       false -> TabDef
+    end,
+    parse(Tail, [{Name, NewDef} | Acc]);
+parse([Other|_], _) ->
+    {error, {invalid, Other}}.
+
+need_reset(FromDef, ToDef) ->
+    ValuesF = [lists:keyfind(Key, 1, FromDef) || Key <- ?NEED_RESET],
+    ValuesT = [lists:keyfind(Key, 1, ToDef) || Key <- ?NEED_RESET],
+    lists:foldl(
+      fun({Val, Val}, Acc) -> Acc;
+        ({_, false}, Acc) -> Acc;
+        ({_, _}, _) -> true
+      end, false, lists:zip(ValuesF, ValuesT)).
+
+transform(OldAttrs, Attrs, Old) ->
+    [Name|OldValues] = tuple_to_list(Old),
+    Before = lists:zip(OldAttrs, OldValues),
+    After = lists:foldl(
+             fun(Attr, Acc) ->
+                     case lists:keyfind(Attr, 1, Before) of
+                         false -> [{Attr, undefined}|Acc];
+                         Value -> [Value|Acc]
+                     end
+             end, [], lists:reverse(Attrs)),
+    {Attrs, NewRecord} = lists:unzip(After),
+    list_to_tuple([Name|NewRecord]).
index a23f443ed6851960cd2c34ef9150d5a02ccbdcbf..bdd2d0edd89d27a56182149047d60a78bed893db 100644 (file)
@@ -34,7 +34,7 @@
 -include("ejabberd_oauth.hrl").
 
 init() ->
-    mnesia:create_table(oauth_token,
+    ejabberd_mnesia:create(?MODULE, oauth_token,
                         [{disc_copies, [node()]},
                          {attributes,
                           record_info(fields, oauth_token)}]),
index c6d91909770b0aa6d7046844c53b665ad2796e97..33093abb091e5d060196c8336e6b533234aa5ffc 100644 (file)
@@ -280,7 +280,7 @@ process_iq(From, To, El) ->
 %%--------------------------------------------------------------------
 init([]) ->
     update_tables(),
-    mnesia:create_table(route,
+    ejabberd_mnesia:create(?MODULE, route,
                        [{ram_copies, [node()]},
                         {type, bag},
                         {attributes, record_info(fields, route)}]),
index 283bcac25a79aeb1368d66d7da1d94c5d2306c25..c7a19067095da5c3a8ec78b48f0c56f0e08c4f2d 100644 (file)
@@ -115,7 +115,7 @@ unregister_route(Domain) ->
 %% Description: Initiates the server
 %%--------------------------------------------------------------------
 init([]) ->
-    mnesia:create_table(route_multicast,
+    ejabberd_mnesia:create(?MODULE, route_multicast,
                        [{ram_copies, [node()]},
                         {type, bag},
                         {attributes,
index 97aef3cabdc3191c33a762724450bc4cb7b20470..4df1761cb537677b5c6f7f46de8b78ead232a66d 100644 (file)
@@ -236,14 +236,14 @@ make_key({From, To}, StreamID) ->
 
 init([]) ->
     update_tables(),
-    mnesia:create_table(s2s,
+    ejabberd_mnesia:create(?MODULE, s2s,
                        [{ram_copies, [node()]},
                         {type, bag},
                         {attributes, record_info(fields, s2s)}]),
     mnesia:add_table_copy(s2s, node(), ram_copies),
     mnesia:subscribe(system),
     ejabberd_commands:register_commands(get_commands_spec()),
-    mnesia:create_table(temporarily_blocked,
+    ejabberd_mnesia:create(?MODULE, temporarily_blocked,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, temporarily_blocked)}]),
     {ok, #state{}}.
index 491872aee607095b9797b796aa865501f2471153..ed38ceee9f7ad955d8329f2c0b3168aed6baf953 100644 (file)
@@ -80,10 +80,10 @@ get_sessions(LUser, LServer, LResource) ->
 %%%===================================================================
 init([]) ->
     update_tables(),
-    mnesia:create_table(session,
+    ejabberd_mnesia:create(?MODULE, session,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, session)}]),
-    mnesia:create_table(session_counter,
+    ejabberd_mnesia:create(?MODULE, session_counter,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, session_counter)}]),
     mnesia:add_table_index(session, usr),
index 29099fce3f261edec51fa01bf951ac14d6a1b5e9..93bc10ac51e79ae2124766d32910f542f77dbd3f 100644 (file)
@@ -49,7 +49,7 @@
 -record(sql_pool, {host, pid}).
 
 start_link(Host) ->
-    mnesia:create_table(sql_pool,
+    ejabberd_mnesia:create(?MODULE, sql_pool,
                        [{ram_copies, [node()]}, {type, bag},
                         {local_content, true},
                         {attributes, record_info(fields, sql_pool)}]),
index 23b2a5ba3bbc7ec627e0d873572c1b2844b26e39..47753965d2f6765102336774819f941ac4583393 100644 (file)
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(motd,
+    ejabberd_mnesia:create(?MODULE, motd,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, motd)}]),
-    mnesia:create_table(motd_users,
+    ejabberd_mnesia:create(?MODULE, motd_users,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, motd_users)}]),
index 13d85b3cba916fe305ec2880cb0fa8585f21ed91..038218739a6b169231cf245b33b5f60c0aacd660 100644 (file)
@@ -240,7 +240,7 @@ setup_database() ->
         _ ->
             ok
     end,
-    mnesia:create_table(bosh,
+    ejabberd_mnesia:create(?MODULE, bosh,
                        [{ram_copies, [node()]}, {local_content, true},
                         {attributes, record_info(fields, bosh)}]),
     mnesia:add_table_copy(bosh, node(), ram_copies).
index 660fcb4effa3506be4e2c4f16a80076d8a095775..ed22841e8e813b00daddd6ce8c9e73b421340d84 100644 (file)
@@ -27,7 +27,7 @@ init(_Host, _Opts) ->
         _ ->
             mnesia:delete_table(caps_features)
     end,
-    mnesia:create_table(caps_features,
+    ejabberd_mnesia:create(?MODULE, caps_features,
                         [{disc_only_copies, [node()]},
                          {local_content, true},
                          {attributes,
index bf69bd21c776b97455de3c8e92de9ee9ae49ef5b..4cc7e6049fa5597baede9a8bde2a2e880476c60c 100644 (file)
@@ -30,7 +30,7 @@ init(_Host, _Opts) ->
            %% probably table don't exist
            ok
     end,
-    mnesia:create_table(carboncopy,
+    ejabberd_mnesia:create(?MODULE, carboncopy,
                        [{ram_copies, [node()]}, 
                         {attributes, record_info(fields, carboncopy)}, 
                         {type, bag}]),
index 471b38c00e8d5bc60274b11f67ba99a7cc4be54f..68500f2c448127720dda4e42a34cc3af0f867538 100644 (file)
@@ -89,7 +89,7 @@ stop(_Host) ->
 
 setup_database() ->
     migrate_database(),
-    mnesia:create_table(http_bind,
+    ejabberd_mnesia:create(?MODULE, http_bind,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, http_bind)}]).
 
index 95cceb54c645f073181ba10d021292da124b324b..e23f5a268ac7aa46471f9c7f697333200380facc 100644 (file)
@@ -21,7 +21,7 @@
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(irc_custom,
+    ejabberd_mnesia:create(?MODULE, irc_custom,
                        [{disc_copies, [node()]},
                         {attributes, record_info(fields, irc_custom)}]),
     update_table().
index 7a1610abbf5788c6d4ce3b1afa18c34c3adffc41..269ed4ba0351a46b0233f77dd8fdf34da9e0e0ab 100644 (file)
@@ -19,7 +19,7 @@
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(last_activity,
+    ejabberd_mnesia:create(?MODULE, last_activity,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, last_activity)}]),
index 8b9c6676c66efe4c9aef13560feb6dcc4cd43439..89ab92ff1cdb695100cc531dd1eb2d860bdf89f0 100644 (file)
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(archive_msg,
+    ejabberd_mnesia:create(?MODULE, archive_msg,
                        [{disc_only_copies, [node()]},
                         {type, bag},
                         {attributes, record_info(fields, archive_msg)}]),
-    mnesia:create_table(archive_prefs,
+    ejabberd_mnesia:create(?MODULE, archive_prefs,
                        [{disc_only_copies, [node()]},
                         {attributes, record_info(fields, archive_prefs)}]).
 
index ab358b957a2d5000db79a137c14a52dbb7cc9759..298749329cd675b36ec3d73b155a8d731a839f28 100644 (file)
@@ -177,7 +177,7 @@ init([Host, Opts]) ->
     Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
     Mod:init(Host, [{host, MyHost}|Opts]),
     update_tables(),
-    mnesia:create_table(muc_online_room,
+    ejabberd_mnesia:create(?MODULE, muc_online_room,
                        [{ram_copies, [node()]},
                         {type, ordered_set},
                         {attributes, record_info(fields, muc_online_room)}]),
index 072dddaae650a750bb8471db52e0556105740996..8f570746c2d678f59d1b380b58e67bda0a934453 100644 (file)
 %%%===================================================================
 init(_Host, Opts) ->
     MyHost = proplists:get_value(host, Opts),
-    mnesia:create_table(muc_room,
+    ejabberd_mnesia:create(?MODULE, muc_room,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, muc_room)}]),
-    mnesia:create_table(muc_registered,
+    ejabberd_mnesia:create(?MODULE, muc_registered,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, muc_registered)}]),
index 0aa2270ae35573b650622c0b5b3316935b4e05a2..fbd2402eead68e89687c6806ca9bb1595e9145bc 100644 (file)
@@ -840,7 +840,7 @@ received_awaiter(JID, Waiter, LServiceS) ->
 %%%-------------------------
 
 create_cache() ->
-    mnesia:create_table(multicastc,
+    ejabberd_mnesia:create(?MODULE, multicastc,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, multicastc)}]).
 
index e84f7078aedfbb0314aaf9e84018b4bcb4bda464..fb75f618e80f7dc75f6eedff226838370516b0d7 100644 (file)
@@ -25,7 +25,7 @@
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(offline_msg,
+    ejabberd_mnesia:create(?MODULE, offline_msg,
                        [{disc_only_copies, [node()]}, {type, bag},
                         {attributes, record_info(fields, offline_msg)}]),
     update_table().
index a93e92139fc3e47b05c9d2ad2081b35b422f17ed..eca6f8ecd78484f51f8df003f109c88de80b505b 100644 (file)
@@ -25,7 +25,7 @@
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(privacy,
+    ejabberd_mnesia:create(?MODULE, privacy,
                        [{disc_copies, [node()]},
                         {attributes, record_info(fields, privacy)}]),
     update_table().
index 84871c1e71440454434d8094917df4a564cd08b7..42e5ddfd8ba6bada472bc44ff7f4339fe0761623 100644 (file)
@@ -21,7 +21,7 @@
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(private_storage,
+    ejabberd_mnesia:create(?MODULE, private_storage,
                        [{disc_only_copies, [node()]},
                         {attributes,
                          record_info(fields, private_storage)}]),
index 7ef4d390ee8e0fb9565c8911a629125b02f64e89..b1d33b5d954546a683699ec5a74092ec2b39bc21 100644 (file)
@@ -62,7 +62,7 @@ start_link(Host, Opts) ->
                          []).
 
 init([Opts]) ->
-    mnesia:create_table(bytestream,
+    ejabberd_mnesia:create(?MODULE, bytestream,
                        [{ram_copies, [node()]},
                         {attributes, record_info(fields, bytestream)}]),
     mnesia:add_table_copy(bytestream, node(), ram_copies),
index ba79cf7bcb5255a7c7e7f408d907498bd4fc8bf6..717796fecef0cbd12b8d30bee391698643444fea 100644 (file)
@@ -268,7 +268,7 @@ init([ServerHost, Opts]) ->
     BaseOptions = DefaultModule:options(),
     DefaultNodeCfg = gen_mod:get_opt(default_node_config, Opts,
            fun(A) when is_list(A) -> filter_node_options(A, BaseOptions) end, []),
-    mnesia:create_table(pubsub_last_item,
+    ejabberd_mnesia:create(?MODULE, pubsub_last_item,
        [{ram_copies, [node()]},
            {attributes, record_info(fields, pubsub_last_item)}]),
     mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
index ba261e0f3337e597462aef571b7d3d71f57a0270..b96ebecbdb7fd1ef172e0dae02abd01582468c44 100644 (file)
@@ -54,7 +54,7 @@ start(Host, Opts) ->
                       stream_feature_register, 50),
     ejabberd_hooks:add(c2s_unauthenticated_iq, Host,
                       ?MODULE, unauthenticated_iq_register, 50),
-    mnesia:create_table(mod_register_ip,
+    ejabberd_mnesia:create(?MODULE, mod_register_ip,
                        [{ram_copies, [node()]}, {local_content, true},
                         {attributes, [key, value]}]),
     mnesia:add_table_copy(mod_register_ip, node(),
index e274ac5ebcbcfdaca018d8db2ed9815a5192086d..04bdf72e7657d33948fd32a0e0419fd816a1533b 100644 (file)
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(roster,
+    ejabberd_mnesia:create(?MODULE, roster,
                        [{disc_copies, [node()]},
                         {attributes, record_info(fields, roster)}]),
-    mnesia:create_table(roster_version,
+    ejabberd_mnesia:create(?MODULE, roster_version,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, roster_version)}]),
index 0f9e93bf6ce8aa0f471548fee690d8676a35169e..ed4525041bacb66b19e31f21e9c1775fba6dcce6 100644 (file)
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(sr_group,
+    ejabberd_mnesia:create(?MODULE, sr_group,
                        [{disc_copies, [node()]},
                         {attributes, record_info(fields, sr_group)}]),
-    mnesia:create_table(sr_user,
+    ejabberd_mnesia:create(?MODULE, sr_user,
                        [{disc_copies, [node()]}, {type, bag},
                         {attributes, record_info(fields, sr_user)}]),
     update_tables(),
index e6532c934e17d6289098f0de8aac379a564f2559..4ae8e077bca12a158349d9fdc35c44f5af5d2178 100644 (file)
@@ -179,7 +179,7 @@ ping(SIPSocket) ->
 %%%===================================================================
 init([]) ->
     update_table(),
-    mnesia:create_table(sip_session,
+    ejabberd_mnesia:create(?MODULE, sip_session,
                        [{ram_copies, [node()]},
                         {type, bag},
                         {attributes, record_info(fields, sip_session)}]),
index a4a5f25626bf9a4db1ca00629365dd260fc61ec6..40ea363818a01f884cdb6cb743bbd403c6d59d34 100644 (file)
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(vcard,
+    ejabberd_mnesia:create(?MODULE, vcard,
                        [{disc_only_copies, [node()]},
                         {attributes, record_info(fields, vcard)}]),
-    mnesia:create_table(vcard_search,
+    ejabberd_mnesia:create(?MODULE, vcard_search,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, vcard_search)}]),
index 3f8d6fcab23b6949630150278bcad059c1bf6d2c..454d97e25c455140a1d4226bc3b439b67587bc05 100644 (file)
@@ -19,7 +19,7 @@
 %%% API
 %%%===================================================================
 init(_Host, _Opts) ->
-    mnesia:create_table(vcard_xupdate,
+    ejabberd_mnesia:create(?MODULE, vcard_xupdate,
                        [{disc_copies, [node()]},
                         {attributes,
                          record_info(fields, vcard_xupdate)}]),
index 9c1bc9b98700af0234cbd8a220d9a2d939dd05e1..55093b0e7080555638aa5ffc4a08cba124113cb9 100644 (file)
 
 init(_Host, _ServerHost, _Opts) ->
     %pubsub_subscription:init(Host, ServerHost, Opts),
-    mnesia:create_table(pubsub_state,
+    ejabberd_mnesia:create(?MODULE, pubsub_state,
        [{disc_copies, [node()]},
            {type, ordered_set},
            {attributes, record_info(fields, pubsub_state)}]),
-    mnesia:create_table(pubsub_item,
+    ejabberd_mnesia:create(?MODULE, pubsub_item,
        [{disc_only_copies, [node()]},
            {attributes, record_info(fields, pubsub_item)}]),
     ItemsFields = record_info(fields, pubsub_item),
index 81972ca3c1db35afd4fd81e8b440a2a027877769..eb28e3408c9f16b4b5ffc2b80ba91376992c3f53 100644 (file)
@@ -49,7 +49,7 @@
     delete_node/2]).
 
 init(_Host, _ServerHost, _Options) ->
-    mnesia:create_table(pubsub_node,
+    ejabberd_mnesia:create(?MODULE, pubsub_node,
        [{disc_copies, [node()]},
            {attributes, record_info(fields, pubsub_node)}]),
     mnesia:add_table_index(pubsub_node, id),
index 983356a183d7a7d93c051b22f3a30316fda87c32..45361e1416009c6c9b7273d36975e1832021b7b6 100644 (file)
@@ -34,7 +34,7 @@
 -export([init/3, new/1, free/2]).
 
 init(_Host, _ServerHost, _Opts) ->
-    mnesia:create_table(pubsub_index,
+    ejabberd_mnesia:create(?MODULE, pubsub_index,
        [{disc_copies, [node()]},
            {attributes, record_info(fields, pubsub_index)}]).
 
index c493b58f9eb2a67ee39e8200c399b79b92366c4e..a329f3c39b6ca14e7a702ac3328eec9cfb88f907 100644 (file)
@@ -253,7 +253,7 @@ update_node_database(Host, ServerHost) ->
              end,
          {atomic, NewRecords} = mnesia:transaction(F),
          {atomic, ok} = mnesia:delete_table(pubsub_node),
-         {atomic, ok} = mnesia:create_table(pubsub_node,
+         {atomic, ok} = ejabberd_mnesia:create(?MODULE, pubsub_node,
                                             [{disc_copies, [node()]},
                                              {attributes,
                                               record_info(fields,
@@ -421,7 +421,7 @@ update_state_database(_Host, _ServerHost) ->
            {atomic, NewRecs} = mnesia:transaction(fun mnesia:foldl/3,
                                                   [F, [], pubsub_state]),
            {atomic, ok} = mnesia:delete_table(pubsub_state),
-           {atomic, ok} = mnesia:create_table(pubsub_state,
+           {atomic, ok} = ejabberd_mnesia:create(?MODULE, pubsub_state,
                                               [{disc_copies, [node()]},
                                                {attributes, record_info(fields, pubsub_state)}]),
            FNew = fun () ->
index 077ac5ba9239c3f5dcc63492f9651bf9754bcb8c..0ca066dae79a8db24fed8ed16bdae5c458ea68a9 100644 (file)
@@ -126,7 +126,7 @@ parse_options_xform(XFields) ->
 %% Internal functions
 %%====================================================================
 create_table() ->
-    case mnesia:create_table(pubsub_subscription,
+    case ejabberd_mnesia:create(?MODULE, pubsub_subscription,
            [{disc_copies, [node()]},
                {attributes,
                    record_info(fields, pubsub_subscription)},
index eb82b8faabed28d1942b415f07bf3a8ba2eaf47c..19c9a049da02bb366d0d7aa55fe07544ca01cb2c 100644 (file)
@@ -50,7 +50,7 @@
 -spec start() -> ok.
 
 start() ->
-    mnesia:create_table(shaper,
+    ejabberd_mnesia:create(?MODULE, shaper,
                         [{ram_copies, [node()]},
                          {local_content, true},
                         {attributes, record_info(fields, shaper)}]),