defmodule Ammoprices.Prices.PriceSnapshot do @moduledoc false use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "price_snapshots" do belongs_to :product, Ammoprices.Catalog.Product field :price_cents, :integer field :price_per_round_cents, :integer field :in_stock, :boolean, default: true field :recorded_at, :utc_datetime timestamps(type: :utc_datetime, updated_at: false) end def changeset(snapshot, attrs) do snapshot |> cast(attrs, [:price_cents, :price_per_round_cents, :in_stock, :recorded_at]) |> validate_required([:price_cents, :price_per_round_cents, :recorded_at]) |> validate_number(:price_cents, greater_than: 0) |> validate_number(:price_per_round_cents, greater_than: 0) end end