caslu

caslu

Mix phx.gen: Add not-null modifier to Phoenix generators

Recently (last week) this PR was merged in Ruby on Rails repository and i thought it could be nice to have in phoenix, basically what it does is to add a “!” operator at the end of each type, so in summary we would type:

$ mix phx.gen.schema Blog.Post blog_posts title:string! views:integer!

and the current output would be generated:

defmodule MyApp.Repo.Migrations.CreateBlogPosts do
  use Ecto.Migration

  def change do
    create table(:blog_posts) do
      add :title, :string, null: false
      add :views, :integer, null: false

      timestamps(type: :utc_datetime)
    end
  end
end

If you think this make sense as i do and like the idea i think would be great for me to work in this feature since i’m always looking to ways to contribute with code for phoenix, but i would need some help and i’d be really greateful if you guys could help me do it.

IMPORTANT: There’s my first feature suggestion and i don’t know very well how things are done here, sorry if the post does not follow any standard or something like that.

First 6 of 6 Posts Switch mode

rhcarvalho

rhcarvalho

It’s a reasonable feature. I occasionally add null: false after generating migrations.

Let’s hear what other people think.

If you have buy-in from the Phoenix team I can help you both suggesting pointers for where to look at in the code base as well a reviewing a PR.

dimitarvp

dimitarvp

I do like the idea and I believe I’ve seen it in other ecosystems as well. But there must always be kept a balance between over-loading a DSL and the usefulness that the new feature will bring. It’s not a clear win in favor of adding the bang variant.

caslu

caslu OP

Thanks for your reply and point of view, so if i got it you meant that’s not worthy to add bang variable in generators right? I can be wrong but In my opinion, this feature is classified as a small change that would help a lot in everyday life of phoenix devs, i already had to generate long schemas and was kind of boring to add null: false in almost every field. Anyway, thanks for your reply :waving_hand:

caslu

caslu OP

Thanks bro, i think would be great to have this feature cause we’ll be able to generate almost everything in migration only using mix phx task.

I’d really love this help, would be very welcome mate :saluting_face:

rhcarvalho

rhcarvalho

(If your driving motivation is to contribute something, and you are interested in the code generators, this open issue might serve as a good entrypoint to the topic Calling phx.mix.gen without specifying attributes will succeed but create broken code · Issue #5870 · phoenixframework/phoenix · GitHub)

caslu

caslu OP

Gonna take a look bro, i’m really looking forward code contribution in phoenix. Can i send you a DM in forum chat ?

— All posts loaded —

Where Next?

Trending in Proposals: Ideas Top

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement