Erlang: side effect(s) to calling mnesia:create_schema more than once?
Is there a side effect to calling mnesia:create_schema()
on each application start?
From what I keep reading, this fun开发者_Python百科ction should only be called once per database instance. Is it a big issue to call it more than once on an existing database?
I've done this before in development and it spits out warnings on the tables that already exist. However I wouldn't make it a practice to rerun it in Production since it's possible that it may have some side-effects I'm unaware of and even if it doesn't now there is no guarantee that it won't in future releases.
Why do you want to run it multiple times?
It has no side effect, but later calls will result in {error, {Node,{already_exists,Node}}}. You can use something like
ensure_schema() ->
Node = node(),
case mnesia:create_schema([Node]) of
ok -> ok;
{error, {Node, {already_exists, Node}}} -> ok;
Error -> Error
end.
Well it could throw an exception on the second call. Just catch it.
精彩评论