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

Dale Harvey harveyd@REDACTED
Sat Jun 27 18:22:05 CEST 2009


I use this, seen a few variants of the same around different codebases

is_fresh_startup() ->
    case mnesia:system_info(tables) of
        [schema] -> true;
        Tbls ->
            case mnesia:table_info(schema, cookie) of
                {_, node()} -> {exists, Tbls};
                _                 -> true
            end
    end.

which can be used as

    case is_fresh_startup() of
        true             ->
            %% create schema etc etc
        {exists, Tables} ->
            ok = mnesia:wait_for_tables(Tables, 1000000)
    end,

there may be better ways, but this seems to work fine

2009/6/27 Seth Falcon <seth@REDACTED>

> Hi all,
>
> I have a question about how folks bootstrap an OTP application that
> depends on mnesia.  Consider an OTP application foo that uses mnesia.
> Since mnesia is specified in the needed applications list, mnesia must
> be started before you start foo.
>
> For the first run of foo, one needs to call mnesia:create_schema/1
> _before_ mnesia is started.
>
> I'd like to be able to start foo on a clean system and have the schema
> created if needed, but don't see a way to handle this.  I suspect that
> I need to adjust my expectations :-)
>
> Is there a recommended way to handle mnesia initialization?  Is the
> standard practice to create the schema outside of the application
> start up flow or am I missing a way to handle this as part of foo's
> application initialization?
>
> Thanks,
>
> + seth
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list