How to handle mnesia schemas in a standard way?

Suppose I have an application A that depends on mnesia with a disk layout present. What I would do is make sure that mnesia works and allows a table disc_copies of A . I am also considering a case where multiple applications must have access to mnesia.

What would be the most portable (and standard) way to achieve this kind of thing, without hard coding mnesia startup and creating a circuit in application callback module A ?

With interactive development, I just do

mnesia:create_schema([node()]).

inside the Erlang shell to initialize the schema on disk, then run the mnesia application using

mnesia:start().

and finally, launch others that depend on the database present.

+3
source share
2 answers

I found a solution myself. This is by no means a standard method, but it works.

Call

mnesia:change_table_copy_type(schema, node(), disc_copies).

upon application startup will ensure that the circuit is disk-based, while allowing mnesia to start by loading the script. This blog post was very helpful.

0
source

You can specify dependent applications in your .app file, see field {applications, Apps}. This way you can make sure that the application does not start without starting mnesia, and when creating the release, it can generate a script that starts mnesia in front of your application.

mnesia , -, . escript, , .

, mnesia: wait_for_tables/2, , .

+3

Source: https://habr.com/ru/post/1752116/


All Articles