mnesia developments

Ulf Wiger etxuwig@REDACTED
Wed Jun 4 09:36:23 CEST 2003


On Tue, 3 Jun 2003 erlang@REDACTED wrote:

>In my further researches into the user manual I _think_ I
>have developed a clearer understanding of what the source
>of my confusion was.
>
>Correct me if I am wrong, please:
>
>the _.hrl file can be used to express a schema which will
>be loaded when mnesia is started

Well, perhaps not quite.

There is no mnesia equivalent to SQL for schema declaration.
You call functions to create schema and tables.

A common way to create a mnesia schema is to write a
function, say myModule:schema_init(), that does some or all
of these things:

- possibly delete any existing schema
  (mnesia:delete_schema(Nodes))
- create a mnesia schema (mnesia:create_schema(Nodes)
- start mnesia (mnesia:start())
- create the needed tables (mnesia:create_table(...))
- possibly fill the tables with initial data

This function should only be run once, when installing the
system. It's good practice to collect the record definitions
for the mnesia tables in a common .hrl file, which can be
included by myModule above.

Once all this is done, you should be able to start your
erlang node and make sure mnesia is started. Mnesia should
then read the schema you have created.

Note that mnesia expects the erlang node name to be the same
each time. It tags the schema with the node name used at
creation time.

>mnesia's schema can be created on the fly with shell
>commands (or some suitable function which encapsulates a
>set of them).

Yes, the mnesia interface can be used during runtime, so you
can create new tables, delete old ones, change replication
properties or even the data representation in a table on the
fly, without stopping your system.


>What I'm not clear on is if there is some sneaky lack of
>equivalence between the two methods which isn't made
>entirely clear in the manual.

There is basically only one method:
- make sure mnesia is running.
- call the appropriate functions to create tables, once only
  for each table.
- after that, just start mnesia each time, and it should be
  able to load the schema definitions.

/Uffe
-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes





More information about the erlang-questions mailing list