Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect whether the mnesia schema and table have been created in code?

Tags:

erlang

mnesia

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?

like image 820
why Avatar asked Feb 08 '12 01:02

why


People also ask

What is Mnesia table?

Mnesia is a distributed, soft real-time database management system written in the Erlang programming language. It is distributed as part of the Open Telecom Platform. Mnesia.

What is Mnesia in Linux?

Mnesia is a complete database management system (DBMS) included in Erlang OTP, an open source development environment for concurrent programming based on the Erlang language.


2 Answers

One way to handle this is -

  1. Try creating table using mnesia:create_table(Table_name, ...)

  2. If the table already exists (1) would return {aborted, {already_exists, Table_name}}

  3. If table doesn't exit, it will be created and {atomic,ok} will be returned if successful

  4. If there is any error in table creation in (3), {aborted, Reason} will be returned.

Handle each of these return values as required.

like image 192
spkhaira Avatar answered Sep 21 '22 16:09

spkhaira


check out mnesia:system_info/1, mnesia:schema/0, mnesia:schema/1 and mnesia:table_info/2.

like image 35
Muzaaya Joshua Avatar answered Sep 19 '22 16:09

Muzaaya Joshua