How to detect whether the mnesia schema and table have been created in code?
Domanda
I want to create an mnesia schema and table in my code after the system starts, so I need to detect weather the mnesia schema and table have been created. If not, I want to create them. Is this a good idea? And how can I detect the mnesia schema and table?
Soluzione
One way to handle this is -
Try creating table using
mnesia:create_table(Table_name, ...)
If the table already exists (1) would return
{aborted, {already_exists, Table_name}}
If table doesn't exit, it will be created and
{atomic,ok}
will be returned if successfulIf there is any error in table creation in (3),
{aborted, Reason}
will be returned.
Handle each of these return values as required.
Altri suggerimenti
check out mnesia:system_info/1
, mnesia:schema/0
, mnesia:schema/1
and mnesia:table_info/2
.