plug_gulp

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

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.

Where Next?

Popular in Questions Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
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

We're in Beta

About us Mission Statement