Support for comments (or other metadata) in Ecto.Schema fields? This could help with reflection

I think I may have asked about this before, but that was at least a year ago and I can’t remember if it went anywhere. The idea I had was to support adding a :comment option to an Ecto.Schema field. This could help document the field and it would be useful in reflection and any plugins/add-ons that wanted to augment the Ecto experience. If :comment were too specific, some other “meta” option (e.g. named meta or even opts) would be useful.

At the end of the day, all I really want to augment Ecto.Schema reflection so I can do something like this:

schema "something" do
    field :my_field, :integer, default: "foo", comment: "Useful for reflection/introspection"
    # or maybe
    field :other_field, :string, meta: %{comments: "anything"}

and then:

iex> MySchema.__schema__(:comments, :my_field)
# or maybe
iex> MySchema.__schema__(:info, :my_field)
# or
iex> MySchema.__schema__(:meta, :my_field)

and see the data that I defined. It could be helpful if that function even returned a %Field{} struct or something.

I couldn’t find a feature request in GitHub - elixir-ecto/ecto: A toolkit for data mapping and language integrated query. (even a closed one). Is anyone else excited about something like this?


Crosslinking here: Ecto field descriptions

1 Like

I should specify here that although many databases allow comments to be attached to tables and fields, the push here is for the data to live inside Elixir. In other words, can we do this in a way that would work even for an embedded schema?