Add new 'default_db' option
This commit is contained in:
parent
176114d28e
commit
4af15df546
|
@ -75,7 +75,7 @@ is_riak_configured(Host) ->
|
|||
fun(L) when is_list(L) -> L end, []),
|
||||
ModuleWithRiakDBConfigured = lists:any(
|
||||
fun({_Module, Opts}) ->
|
||||
gen_mod:db_type(Opts) == riak
|
||||
gen_mod:db_type(Host, Opts) == riak
|
||||
end, Modules),
|
||||
ServerConfigured or PortConfigured
|
||||
or AuthConfigured or ModuleWithRiakDBConfigured.
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
get_opt_host/3, db_type/1, db_type/2, get_module_opt/5,
|
||||
get_module_opt_host/3, loaded_modules/1,
|
||||
loaded_modules_with_opts/1, get_hosts/2,
|
||||
get_module_proc/2, is_loaded/2]).
|
||||
get_module_proc/2, is_loaded/2, default_db/1]).
|
||||
|
||||
%%-export([behaviour_info/1]).
|
||||
|
||||
|
@ -212,24 +212,36 @@ get_opt_host(Host, Opts, Default) ->
|
|||
-spec db_type(opts()) -> odbc | mnesia | riak.
|
||||
|
||||
db_type(Opts) ->
|
||||
get_opt(db_type, Opts,
|
||||
fun(odbc) -> odbc;
|
||||
(internal) -> mnesia;
|
||||
(mnesia) -> mnesia;
|
||||
(riak) -> riak
|
||||
end,
|
||||
mnesia).
|
||||
db_type(global, Opts).
|
||||
|
||||
-spec db_type(binary(), atom()) -> odbc | mnesia | riak.
|
||||
-spec db_type(binary() | global, atom() | opts()) -> odbc | mnesia | riak.
|
||||
|
||||
db_type(Host, Module) ->
|
||||
db_type(Host, Module) when is_atom(Module) ->
|
||||
get_module_opt(Host, Module, db_type,
|
||||
fun(odbc) -> odbc;
|
||||
(internal) -> mnesia;
|
||||
(mnesia) -> mnesia;
|
||||
(riak) -> riak
|
||||
end,
|
||||
mnesia).
|
||||
default_db(Host));
|
||||
db_type(Host, Opts) when is_list(Opts) ->
|
||||
get_opt(db_type, Opts,
|
||||
fun(odbc) -> odbc;
|
||||
(internal) -> mnesia;
|
||||
(mnesia) -> mnesia;
|
||||
(riak) -> riak
|
||||
end,
|
||||
default_db(Host)).
|
||||
|
||||
-spec default_db(binary() | global) -> odbc | mnesia | riak.
|
||||
|
||||
default_db(Host) ->
|
||||
ejabberd_config:get_option({default_db, Host},
|
||||
fun(odbc) -> odbc;
|
||||
(mnesia) -> mnesia;
|
||||
(riak) -> riak;
|
||||
(internal) -> mnesia
|
||||
end, mnesia).
|
||||
|
||||
-spec loaded_modules(binary()) -> [atom()].
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
tokenize(Node) -> str:tokens(Node, <<"/#">>).
|
||||
|
||||
start(Host, Opts) ->
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(motd,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -321,7 +321,7 @@ init_db(_, _) ->
|
|||
ok.
|
||||
|
||||
init([Host, Opts]) ->
|
||||
init_db(gen_mod:db_type(Opts), Host),
|
||||
init_db(gen_mod:db_type(Host, Opts), Host),
|
||||
MaxSize = gen_mod:get_opt(cache_size, Opts,
|
||||
fun(I) when is_integer(I), I>0 -> I end,
|
||||
1000),
|
||||
|
|
|
@ -115,7 +115,7 @@ init([Host, Opts]) ->
|
|||
ejabberd:start_app(p1_iconv),
|
||||
MyHost = gen_mod:get_opt_host(Host, Opts,
|
||||
<<"irc.@HOST@">>),
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(irc_custom,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
start(Host, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
||||
one_queue),
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(last_activity,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -283,7 +283,7 @@ can_use_nick(LServer, Host, JID, Nick, odbc) ->
|
|||
init([Host, Opts]) ->
|
||||
MyHost = gen_mod:get_opt_host(Host, Opts,
|
||||
<<"conference.@HOST@">>),
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(muc_room,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -108,7 +108,7 @@ stop(Host) ->
|
|||
%%====================================================================
|
||||
|
||||
init([Host, Opts]) ->
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(offline_msg,
|
||||
[{disc_only_copies, [node()]}, {type, bag},
|
||||
|
|
|
@ -58,7 +58,7 @@ privacy_schema() ->
|
|||
start(Host, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
||||
one_queue),
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(privacy,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
start(Host, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
||||
one_queue),
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(private_storage,
|
||||
[{disc_only_copies, [node()]},
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
start(Host, Opts) ->
|
||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
||||
one_queue),
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(roster,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
group_host = {<<"">>, <<"">>} :: {binary(), binary()}}).
|
||||
|
||||
start(Host, Opts) ->
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(sr_group,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
-define(PROCNAME, ejabberd_mod_vcard).
|
||||
|
||||
start(Host, Opts) ->
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(vcard,
|
||||
[{disc_only_copies, [node()]},
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
%%====================================================================
|
||||
|
||||
start(Host, Opts) ->
|
||||
case gen_mod:db_type(Opts) of
|
||||
case gen_mod:db_type(Host, Opts) of
|
||||
mnesia ->
|
||||
mnesia:create_table(vcard_xupdate,
|
||||
[{disc_copies, [node()]},
|
||||
|
|
Loading…
Reference in New Issue