 
       _ ->
         case transaction do
-          {:error, :model, changeset, %{}} -> {:error, Map.merge(changeset, %{repo: repo})}
+          {:error, _, changeset, %{}} -> {:error, Map.merge(changeset, %{repo: repo})}
           _ -> transaction
         end
     end


      _ ->
        multi
        |> Ecto.Multi.update(:model, changeset, Keyword.take(options, [:returning]))
        |> Ecto.Multi.run(:version, fn repo, %{model: _model} ->
          version = make_version_struct(%{event: "update"}, changeset, options)
          repo.insert(version)
        end)

  def delete(
        %Ecto.Multi{} = multi,
        struct,
        options \\ [
          origin: nil,
          meta: nil,
          originator: nil,
          prefix: nil,
          model_key: :model,
          version_key: :version,
          ecto_options: []
        ]
      ) do
    model_key = options[:model_key] || :model
    version_key = options[:version_key] || :version
    ecto_options = options[:ecto_options] || []

    multi
    |> Ecto.Multi.delete(model_key, struct, ecto_options)
    |> Ecto.Multi.run(version_key, fn repo, %{} ->
      version = make_version_struct(%{event: "delete"}, struct, options)
      repo.insert(version, options)
    end)
