plug_gulp
How to create a schema using generator in an ecto project under umbrella project?
Hello All,
How to create a schema using generator in an ecto project under umbrella project? This is what I tried:
I created an umbrella project, and within that project I created an ecto project using the following commands:
mix phx.new hello --umbrella
cd hello_umbrella
mix ecto.create
cd apps
mix phx.new.ecto hello_ecto
cd hello_ecto
mix ecto.create
Now, how do I create a schema in the hello_ecto repo using the generator phx.gen.schema?
The generator command is not available in the hello_ecto project directory. It is available in the hello_umbrella root directory and in the apps/hello_web directory. I tried issuing the schema generator command from the umbrella root directory but I get the error:
(Mix) mix phx.gen.schema can only be run inside an application directory
So I tried from the apps/hello_web directory, but the schema files are generated in the apps/hello/lib/hello and apps/hello/priv/repo/migrations directories.
How do I generate schema for the hello_ecto umbrella project under the hello_ecto directory?
Edit: I ran the following command under hello_web directory:
mix phx.gen.schema HelloSchema hello_schemas name:unique desc --context-app hello_ecto
Now I get the following error:
** (FunctionClauseError) no function clause matching in Mix.Phoenix.context_lib_path/2
The following arguments were given to Mix.Phoenix.context_lib_path/2:
1
"hello_ecto"2
"hello_schema.ex"Attempted function clauses (showing 1 out of 1):
def context_lib_path(ctx_app, rel_path) when is_atom(ctx_app)
lib/mix/phoenix.ex:224: Mix.Phoenix.context_lib_path/2
lib/mix/phoenix/schema.ex:53: Mix.Phoenix.Schema.new/4
lib/mix/tasks/phx.gen.schema.ex:93: Mix.Tasks.Phx.Gen.Schema.run/1
(mix) lib/mix/task.ex:301: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:75: Mix.CLI.run_task/2
Is this the right way to generate schema in the correct umbrella ecto project? Any help on how to resolve this?
Most Liked
plug_gulp
Thank You for the help!
Another workaround I found out to generate ecto repos in their correct destination folders is by modifying the app’s mix.exs and config.exs files to include the concerned ecto project as umbrella dependency and as generator context app respectively. So the mix.exs file of the hello_web app should contain the following in it’s deps:
{:hello_ecto, in_umbrella: true},
and the config.exs should contain the following:
config :hello_web, :generators,
context_app: :hello_ecto
Now the Phoenix schema generator from hello_web app directory creates schema files in the correct hello_ecto project directory. But this does not feel like the right solution to me. The more appropriate solution would be to either enable schema generator option with command line parameter of --context-app from the umbrella root, or provide the schema generator option for all projects within the umbrella projects. Interestingly the command line option --context-app did not work for me from the hello_web app directory as mentioned in my first post.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









