I won’t be able to address all your questions because my experience is with RAM-only tables, but I can share what works for me anyway in case it helps.
All Mnesia-related code are isolated in it’s own module (it’s called Store in my case). It exposes an init/1 function that creates the tables and a stop/0 function that is only used by the tests, which deletes the tables and stops Mnesia. Since all the tables are RAM-only, I don’t use create_schema.
In each test file, I have something like this:
setup_all do
Store.init()
on_exit(&Store.stop/0)
:ok
end
If you are relying on the order of the tests in each test file, you can add the following line to your test_helper.exs file to make sure the tests will run in the given order:
ExUnit.configure(seed: 0)
So each test file starts with an empty database, then I use the functions provided by my Store module to insert, query, update and delete data and test the results.
For production, I have a GenServer that calls that init/1 function in its own init/1 and handles events from Mnesia like node up and node down, but that’s all. The users of the Store module call its functions directly from their processes and not by sending messages to a GenServer.
Finally, I do have :mnesia in my extra_applications.
Hope it helps,
Regards






















