Custom configuration in config.exs in phoenix project ignored
Closed this issue · 6 comments
In a phoenix app created from scratch I added into config.ex
config :ecto_mnesia,
dir: "priv/mnesia",
storage_type: :disc_copies
However after running mix ecto.create
I noticed that the mnesia files have been created in priv/data/mnesia
which is default config I guess. My custom configuration seems to have been ignored.
I guess thats a bug, will fix it.
@vmoravec can you try to change configuration not by setting it for ecto_mnesia
, but rather try to add it to Repo configuration?
In the end I was successful with putting the configuration bits into the config/config.exs
, config/dev.exs
and config/prod.exs
and get it working that way. Seems adding mnesia configuration into every config has fixed it:
# example for config/prod.exs
config :mnesia, dir: 'priv/mnesia/production'
Like in vmoravec/saturn@a73f3fd
However, there is still some incompatibility between the phoenix conventions - I have to explicitly define all table columns, using timestamps
or implicit id
s doesn't work, one has to define everything explicitly (works for me). However, mentioning that in the README file would be very helpful for those who might try to use this very nice lib with phoenix.
@vmoravec I've created a PR to your repo. No need to explicitly set :id field. Also you don't really need to duplicate config, but you can do it if you want to have different database names for each environment.
I have dropped SQL sandbox code (it's not supported) so mix test
will start working.
~/Projects/www/saturn(master ✔) ls -la priv/mnesia
total 0
drwxr-xr-x 2 andrew staff 68 Dec 18 00:43 .
drwxr-xr-x 5 andrew staff 170 Dec 18 00:37 ..
~/Projects/www/saturn(master ✔) mix test
==> Setting Mnesia schema table copy type
==> Ensuring Mnesia schema exists
[:version, :inserted_at]
........[%Saturn.User{__meta__: #Ecto.Schema.Metadata<:built, "users">, email: "some content", id: 1, inserted_at: {{2016, 12, 17}, {22, 43, 36, 565329}}, name: "some content", updated_at: {{2016, 12, 17}, {22, 43, 36, 565337}}}, %Saturn.User{__meta__: #Ecto.Schema.Metadata<:built, "users">, email: nil, id: 2, inserted_at: {{2016, 12, 17}, {22, 43, 36, 569353}}, name: nil, updated_at: {{2016, 12, 17}, {22, 43, 36, 569359}}}]
....
1) test updates chosen resource and redirects when data is valid (Saturn.UserControllerTest)
test/controllers/user_controller_test.exs:47
** (Ecto.MultipleResultsError) expected at most one result but got 2 in query:
from u in Saturn.User,
where: u.email == ^"some content" and u.name == ^"some content"
stacktrace:
(ecto) lib/ecto/repo/queryable.ex:71: Ecto.Repo.Queryable.one/4
test/controllers/user_controller_test.exs:51: (test)
...
Finished in 0.1 seconds
16 tests, 1 failure
Randomized with seed 419296
I'm not aware of what additional changes you made, so did not touch last error. But basically tests expected DB to be empty, and you need to clean it manually (since sandbox is not supported).
Might be interesting for future references (Maybe can be added to a wiki):
How does one clean up mnesia before every spec? The same as sandbox mode in PostgreSQL
@JanStevens It would be a wrong reference, because sandbox mode traps all your queries into a transaction that bound to test process, and cancels that transaction when tests finishes.
I'm have ideas how to implement same behaviour in Mnesia, will see is it possible without hacking native transactions.