Ecto field descriptions

From the Ecto.Schema docs I don’t see a great way to do something like this.

If you wanted a solution that would get you close for not a whole lot of effort, you could create a module attribute for field docs that accumulate across the module then do with them what you will in a before_compile. To keep these simple you’d have to include the field names in the module attribute to link them without messing with the calls to field/3.

defmodule SpamPredicition do
  use Ecto.Schema
  @before_compile MyLib

  @primary_key false
  schema "predictions" do

    @field_doc class: "I think ideally i'd put field descriptions as @doc attributes"
    field(:class, Ecto.Enum, values: [:spam, :not_spam])

    @field_doc reason: "But I could tolerate field descriptions here"
    field(:reason, :string)
    field(:confidence_score, :float)
  end
end

Killing the need to include the field name in the module attribute would be a bit harder. You could potentially create your own field/3, belongs_to/3, has_many/3, etc. macros that took the current module attr, let’s again call @field_doc, and translate it to an accumulating module attr, let’s call @field_doc_acc, before falling back to the wrapped Ecto.Schema macro.