Is there ways to specify path to schema in cowboy app? Maybe it's possible to set in my_app.app.src or any config file?
The path to the mnesia directory has to be provided to erlang VM before mnesia application is started through application configuration parameters. In Mnesia tutorial, this is done with the -Application par val
VM arguments syntax.
What you call a cowboy application is probably an Erlang OTP release (built by relx as per cowboy tutorial). The solutions, quickly described in Cowboy issue #595, are as follows.
The choice between solutions really depends on style as well as some constraints. Any sufficiently complex release would use a configuration file, so it would be a good choice. vm.args
seems easier to deal with. Eventually, you might need to alter the start script (for example to run several nodes from a single deployment), and include some logic to define the mnesia directory.
To do so, add the following term to relx.config
as documented.
{sys_config, "./config/sys.config"}.
sys.config
actually is a standard Erlang configuration file, also documented. Specifying mnesia dir is done by adding a section for mnesia application. If no other configuration is required, the file would be:
[{mnesia, [{dir, "/path/to/dir"}]}].
The vm.args
file is actually passed to the VM through -args_file
option. This is a simple text file with arguments.
You would add the following term to relx.config
as documented.
{vm_args, "./config/vm.args"}.
And put the following content in the vm.args
file:
-mnesia dir foo
relx
actually creates a start script, which passes -config sys.config
and args_file vm.args
to the VM as required. You could modify this script or roll your own to actually pass the -mnesia dir
argument to the VM.