Is there a simple way to make child changeset which will be history?

I’m newbie to DB and Ecto.
I’d like to make history data for user_properties which will be changed by real user, like below.


For user_properties, I’d like to allow only “INSERT” as history.

User INSERT with property is simple.

  def create_user_with_property(attrs) do
    |> User.changeset(attrs)
    |> Ecto.Changeset.cast_assoc(:property)
    |> Repo.insert()

User UPDATE with property is also simple when it allows “UPDATE”.

  def update_user_with_property(user, attrs) do
    |> User.changeset(attrs)
    |> Ecto.Changeset.cast_assoc(:property)
    |> Repo.update()

I read the blog which explains a solution, Entity status history using ecto. For a project of mine I recently needed… | by Benjamin Milde | | Medium .

This solution is nice, but the blog points out its complexity.

This part is mostly so complex because I wanted to keep the return value of {:ok, entity} | {:error, changeset} .

I expect like on_replace: :insert, Ecto.Changeset — Ecto v3.5.7 .

Is there any way to solve this more simple?