Question

Is there a side effect to calling mnesia:create_schema() on each application start?

From what I keep reading, this function should only be called once per database instance. Is it a big issue to call it more than once on an existing database?

Was it helpful?

Solution

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?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top