cover/Elixir.DaProductApp.Transactions.TransactionEvent.html

1 defmodule DaProductApp.Transactions.TransactionEvent do
2 @moduledoc """
3 Event record for transaction aggregate with hash chaining.
4 """
5 use Ecto.Schema
6 import Ecto.Changeset
7
8 160 schema "transaction_events" do
9 field :seq, :integer
10 field :event_type, :string
11 field :payload, :map
12 field :prev_hash, :binary
13 field :hash, :binary
14 belongs_to :transaction, DaProductApp.Transactions.Transaction
15 field :inserted_at, :utc_datetime
16 end
17
18 @required ~w(seq event_type hash inserted_at transaction_id)a
19 @optional ~w(payload prev_hash)a
20
21 def changeset(struct, attrs) do
22 struct
23 |> cast(attrs, @required ++ @optional)
24 |> validate_required(@required)
25 9 |> unique_constraint([:transaction_id, :seq])
26 end
27 end
Line Hits Source