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

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement