defmodule ArcadiaCloud.Provisioning.SagaStepResult do use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id @statuses ~w(running completed failed compensated) schema "saga_step_results" do field :step_idx, :integer field :step_name, :string field :status, :string field :output, :map, default: %{} field :attempts, :integer, default: 0 field :started_at, :utc_datetime field :completed_at, :utc_datetime field :error, :map belongs_to :saga, ArcadiaCloud.Provisioning.SagaRun end @required ~w(saga_id step_idx step_name status)a @optional ~w(output attempts started_at completed_at error)a def changeset(result, attrs) do result |> cast(attrs, @required ++ @optional) |> validate_required(@required) |> validate_inclusion(:status, @statuses) |> unique_constraint([:saga_id, :step_idx]) end end