I used the phx.gen.html generator to create a table and related controller and view data using this command:
mix phx.gen.html TestBeds TestBed testbeds name:string version:string note:string developer:string status:string status_action_value:string
I then wrote code based on the generated table. In retrospect I need another field that populates across the codebase including the form field the generator made.
I want to add an additional field using the generator so that I don’t need to manually update each code piece throughout the codebase. How do I do that?
Also, if I want to remove a field using the generator, how can I do that?
Thank you.
Generators themselves are basically one-way doors. But assuming you use a version control system like git, and assuming the inadequate change has not already been deployed or merged, you can follow a procedure something like this:
mix.ecto.rollback
git add .
git diff
or a similar tool.If you've already merged/deployed changes, the procedure I'd follow would be to create a new change
migration (you can use the ecto generator for that if you like), and manually update the schema, view(s), and changeset functions.
In practice, a change like this is almost certainly going to require changes to your model module, your test fixtures, views, and probably your controller and re-running the generator doesn't buy you much, so I usually just do this sort of change by hand. It's also unusual when the scaffolded views are similar enough to what I would actually consider deploying that the generator saves me much time. In my own team, a few people end up not using the generators at all.