<div dir="ltr"><div dir="ltr">Actually you need first to check does table exists on local node or not. Instead of just create_table you should have some routine like<br><br>init_table(TableName, TableDef) -><br>   AllTables = mnesia:system_info(tables),<br>   case lists:member(TableName, AllTables) of <div>       false -><br>              mnesia:create_table(TableName, TableDef);<br>       true -></div><div>             wait_table(TableName)<br>       end<br>   .<br>In wait_table you should implement mnesia loading table routine.  <br><br>The great starting point how to wrap up mnesia routine is in <br><br><a href="https://github.com/rabbitmq/rabbitmq-server/blob/6cbd36bd79dd72817ec1ebe4a01c0d8a4bc7d69e/src/rabbit_mnesia.erl">https://github.com/rabbitmq/rabbitmq-server/blob/6cbd36bd79dd72817ec1ebe4a01c0d8a4bc7d69e/src/rabbit_mnesia.erl</a><br>and in <br><a href="https://github.com/rabbitmq/rabbitmq-server/blob/6cbd36bd79dd72817ec1ebe4a01c0d8a4bc7d69e/src/rabbit_table.erl">https://github.com/rabbitmq/rabbitmq-server/blob/6cbd36bd79dd72817ec1ebe4a01c0d8a4bc7d69e/src/rabbit_table.erl</a><br><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 8 Nov 2019 at 07:58, Karlo Kuna <<a href="mailto:kuna.prime@gmail.com">kuna.prime@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, <br><div><br></div><div>I have problem with mnesia initialization, </div><div><br></div><div>I have a db_init function that initializes db so that if tables do not exist they are created (ram with disc_copies). For example:</div><div><br></div><div>db_init() -><br>    mnesia:create_table(some_record,[{attributes, record_info(fields, some_record)},<br>                                                                {type, bag}, {disc_copies, [node()]}]).<br><br></div><div>I'm running this function on the app start to make sure the table exists and is ready. </div><div>However half of the time it destroys old table returning {atomic, ok} and another half it returns with already_exists. Also, this happens in the regular fashion, if I have n starts of application, even starts would destroy data and even wold keeps old data. I know that I am missing something probably obvious here but if anyone has any insights on why is this happening and how to fix it I would greatly appreciate it.</div><div><br></div><div>Thank You, </div><div>Karlo. </div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-size:12.8px">Best regards, <br>Alex [Oleksii Semilietov]</span><br></div></div></div></div></div></div>