amnesia icon indicating copy to clipboard operation
amnesia copied to clipboard

Created schema not recognised

Open Lazarus404 opened this issue 9 years ago • 5 comments

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.

Lazarus404 avatar Sep 22 '14 14:09 Lazarus404

Did you create the database after creating the schema? What's your creation code?

meh avatar Sep 22 '14 14:09 meh

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

Lazarus404 avatar Sep 22 '14 14:09 Lazarus404

I then run tun "mix install" followed by "iex -S mix" to get my app running

Lazarus404 avatar Sep 22 '14 14:09 Lazarus404

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

Lazarus404 avatar Sep 22 '14 17:09 Lazarus404

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.

meh avatar Sep 22 '14 18:09 meh