Using mix phx.gen.html with a larger schema

In the examples for using mix phx.gen.html (and gen.schema) the schema usually has only one or two fields, e.g. from the docs:

mix phx.gen.html Accounts User users name:string age:integer

If I want to create a context and schema with more fields (~30), is there another way to get the CRUD generation aside from typing out everything at the command line (with potential typos)?

I can think of three options:

  1. provide a file for input to mix phx.gen.html. Is that possible?
  2. Alternatively, create a smaller schema with the generator and do migrations and bit of schema and heex edting to add everything else, which misses out on the convenience of the generator.
  3. As mentioned above, carefully type out the entire mix gen command and hope all goes well.

Is there a best practice or common way to do this?

The goal behind this is to create work request, something like:

mix gen.phx.html Request Submission submissions name:string date:date…and so forth with many fields.

I realize the default templates may look unwieldy, but this is a quick and dirty demo to get user feedback.

Thanks for any guidance!

1 Like

Most shells have the option to edit the command you’re typing in an editor. I guess that would be some kind of solution.

I don’t know the shortcut by hand but I think for fish it’s alt+e.

You can type out the entire thing in an editor and then paste it in the terminal, or type it in the terminal and put \ as line breaks to make it easier to follow.

Hah, copy and paste. I should have thought of that! Simplicity is best. Thanks!

Edit: thanks also for the advice on line editing, I’m using cmd on Windows and not a unix shell, so it’s a little different. I did test the following, which will work using the line continuation character ^, typing in an editor and pasting into the command window on Windows 11.

mix phx.gen.html ^
Account User users ^
name:string ^
account:string ^
id_number:integer ^