amnesia
amnesia copied to clipboard
Created schema not recognised
Hi,
So, I use the install task to create a schema, but when I try to access the database, I get
** (exit) {:aborted, {:no_exists, [UserStore.User, #PID<0.395.0>]}}
stacktrace:
mnesia.erl:310: :mnesia.abort/1
lib/amnesia/table.ex:484: Amnesia.Table.read!/2
(app) lib/app/connection_store.ex:6: App.UserStore.User.read!/1
(app) lib/app/connection_store.ex:73: App.ConnectionStore.lookup/1
test/app_test.exs:6
My Schema is created with:
deftable User,
[:pid,:username,:bytes,:datetime],
type: :set,
index: [:username] do
@type t :: %User{pid: pid,
username: String.t,
bytes: non_neg_integer,
datetime: {{non_neg_integer, non_neg_integer, non_neg_integer}, {non_neg_integer, non_neg_integer, non_neg_integer}}}
On install, the necessary folders do get created.
Did you create the database after creating the schema? What's your creation code?
use Amnesia
defdatabase UserStore do
@ver "0"
deftable User,
[:pid,:username,:bytes,:datetime],
type: :set,
index: [:username] do
@type t :: %User{pid: pid,
username: String.t,
bytes: non_neg_integer,
datetime: {{non_neg_integer, non_neg_integer, non_neg_integer}, {non_neg_integer, non_neg_integer, non_neg_integer}}}
end
end
defmodule Mix.Tasks.Install do
use Mix.Task
use UserStore
def run(_) do
Amnesia.Schema.create
Amnesia.start
XSignal.UserStore.create(disk: [node])
XSignal.UserStore.wait
Amnesia.stop
end
end
I then run tun "mix install" followed by "iex -S mix" to get my app running
Hi Meh,
Do you have a working example project that I can look over to see what the cause might be? Examples (other than in the readme.md" are few and far between.
Thanks
Sadly no, all examples I have are private stuff I can't share.
Anyway, if what you have there is the code, please use create!
instead of create
, or check the return value because the database is probably raising errors on creation.