sheharyarn / memento

Simple + Powerful interface to the Mnesia Distributed Database 💾
http://hexdocs.pm/memento/
MIT License
734 stars 23 forks source link

Problems creating Mnesia database because the node is not set for distillery release commands. #7

Closed bsechter-unext closed 5 years ago

bsechter-unext commented 5 years ago

I tried to create Distillery release commands, but gave up because the node is not set. Even if I replace the database path or move the files, the database is not usable when the application is started with the proper node name.

There may or may not have been issues with mix commands as well. I did not test them as extensively, but I am using the same base function for both.

Is there a way to create a usable Mnesia database for the node real_node_name@real_host_name when the current node is nonode@nohost in a Distillery release task? Also, being able to batch create Mnesia databases for a list of nodes might be useful, although I do not think that changes anything given a solution for one node.

EDIT

I wound up using the following function to set set the node name for the task.

def set_node_name_for_task(node_name \\ nil) do
  node_name
  |> Kernel.||(System.get_env("NODE_NAME"))
  |> Kernel.||("nonode@nohost")
  |> String.to_atom
  |> Node.start
end

Combined with the following change to the :mnesia configuration, release tasks can be used to create databases. This only works for a single node at a time, however.

config :mnesia,
  dir: '/etc/.mnesia/#{Mix.env}/#{System.get_env("NODE_NAME")}'        # Notice the single quotes

Maybe it is worth adding a note to the documentation?

sheharyarn commented 5 years ago

This should be straight-forward. Instead of reading node name from System.get_env, you should use the built-in node() method and actually specify the node name to distillery using the appropriate config (--name or --sname flags for the commands in general).

See: