defmodule ArcadiaCloud.Billing.CloudCostLine do use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "cloud_cost_lines" do field :invoice_period, :date field :kind, :string field :description, :string field :qty, :decimal field :unit, :string field :unit_cost_cents, :integer field :amount_cents, :integer field :start_at, :utc_datetime field :end_at, :utc_datetime field :project_name, :string field :category, :string field :matched_at, :utc_datetime field :raw, :map belongs_to :invoice, ArcadiaCloud.Billing.CloudInvoice belongs_to :resource, ArcadiaCloud.Cloud.CloudResource timestamps(type: :utc_datetime, updated_at: false) end @required ~w(invoice_id invoice_period amount_cents)a @optional ~w(resource_id kind description qty unit unit_cost_cents start_at end_at project_name category matched_at raw)a def changeset(line, attrs) do line |> cast(attrs, @required ++ @optional) |> validate_required(@required) end end