[erlang-questions] When to create mnesia schema for OTP applications

Seth Falcon seth@REDACTED
Sat Jun 27 23:38:45 CEST 2009


Hi Dale,

Thanks for the suggestion.  This works for me if I stop and start
mnesia in the case of a fresh startup.

* On 2009-06-27 at 17:22 +0100 Dale Harvey wrote:
> is_fresh_startup() ->
>     case mnesia:system_info(tables) of
>         [schema] -> true;
>         Tbls ->
>             case mnesia:table_info(schema, cookie) of
>                 {_, node()} -> {exists, Tbls};

I needed to add Node = node() and put the bound variable in the
pattern to get it to compile:

    {_, Node} -> {exists, Tbls};

> which can be used as
> 
>     case is_fresh_startup() of
>         true             ->
>             %% create schema etc etc

              mnesia:stop(),
              mnesia:create_schema(Nodes),
              mnesia:start(),
              %% create tables

>         {exists, Tables} ->
>             ok = mnesia:wait_for_tables(Tables, 1000000)
>     end,
> 
> there may be better ways, but this seems to work fine

Again, thanks.  This seems to help.  Since this code is in an OTP
application, mnesia must be started before my app can start.
Rebooting mnesia seems a bit strange, but it will only happen if the
schema is not initialized and seems better than requiring a separate
script to get run for the first start.

+ seth


More information about the erlang-questions mailing list