defmodule Microwaveprop.Weather.SolarIndex do @moduledoc false use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} schema "solar_indices" do field :date, :date field :sfi, :float field :sfi_adjusted, :float field :sunspot_number, :integer field :ap_index, :integer field :kp_values, {:array, :float} timestamps(type: :utc_datetime) end @type t :: %__MODULE__{} @required_fields ~w(date)a @optional_fields ~w(sfi sfi_adjusted sunspot_number ap_index kp_values)a @spec changeset(t() | Ecto.Changeset.t(), map()) :: Ecto.Changeset.t() def changeset(solar_index, attrs) do solar_index |> cast(attrs, @required_fields ++ @optional_fields) |> validate_required(@required_fields) |> unique_constraint([:date]) end end