[erlang-questions] [Q] How to delete a table during mnesia startup

Ladislav Lenart lenartlad@REDACTED
Fri Aug 3 16:16:29 CEST 2007


Hello,

upon my application startup, I want to recreate a table from a given
(XML) configuration (i.e. delete it and then create). Mnesia is already
running at this time (it has been started from the boot script). To make
this work I ended up with the following code:
   mnesia:create_table(table, TableSpec),
   mnesia:wait_for_tables([table], Timeout),
   mnesia:delete_table(table),
   mnesia:create_table(table, TableSpec),
   mnesia:wait_for_tables([table], Timeout),

The first create_table/2 call returns {aborted, {already_exists, table}}
but it must be present, because otherwise:
  * first wait_for_tables/2 returns {timeout, [table]},
  * delete_table/1 returns {aborted, {no_exists, table}},
  * create_table/2 returns {aborted, {already_exists, table}} and
  * as a result the table is not deleted at all.

Is the above code a correct "solution" or am I doing something wrong?

Thanks in advance,

Ladislav Lenart




More information about the erlang-questions mailing list