ryanwinchester

ryanwinchester

Including :mnesia in release, without starting it

Initial Problem:

I want to use :mnesia in my application.

If I don’t explicitly include :mnesia in my release, it doesn’t exist.

example:

** (UndefinedFunctionError) function :mnesia.create_schema/1 is undefined
  (module :mnesia is not available)

However, if I add it to :extra_applications so that it gets included in my release, and let it start automatically and create the default schema, I get an error when trying to create tables:

:mnesia.create_table(MyRecord, 
  disc_copies: [node()],
  attributes: [:id, :foo, :bar]
)

with the error:

{:error, {:bad_type, MyRecord, :disc_copies, :nonode@nohost}}

I’m defining the directory in config.exs

config :mnesia, :dir, 'priv/data/mnesia'

And this works fine in dev when I don’t include :mnesia in my :extra_applications and I start it manually.

Solution I want to attempt:

I am trying to include :mnesia in my release, without it starting automatically, so I can start it myself.

I have tried adding it to :included_applications like so:

  def application do
    [
      mod: {MyApp.Application, []},
      extra_applications: [:logger, :runtime_tools],
      included_applications: [:mnesia]
    ]
  end

But this gives me an error

** (Mix) Undefined applications: [mnesia]

Anybody have any insight on how I can get this working?

I’ve been trying to get this working for several hours now and really starting to regret choosing mnesia.

Marked As Solved

danschultzer

danschultzer

Pow Core Team

Yeah, I wish documentation and error messages were better in Mnesia.

If Mnesia has already started with :extra_applications, you should run this instead of :create_schema/1:

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

Otherwise if you only load :mnesia with :included_applications, then you should run this:

:mnesia.create_schema([node()])
:mnesia.start()

After that, :mnesia.create_table/2 should work. Remember to also run :mnesia.wait_for_tables/2 to ensure that the node/cluster is ready.

And as I mentioned in the other thread, I believe the error with Mnesia missing from the release is because of a bug in Elixir 1.9.0. 1.9.1 should resolve that.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement