farmbot_os/farmbot_core/lib/asset_storage/device.ex

25 lines
555 B
Elixir
Raw Normal View History

defmodule Farmbot.Asset.Device do
2017-10-25 21:43:30 -06:00
@moduledoc """
2018-04-18 12:56:08 -06:00
The current device. Should only ever be _one_ of these. If not there is a huge
problem probably higher up the stack.
2017-10-25 21:43:30 -06:00
"""
alias Farmbot.Asset.Device
2017-10-25 21:43:30 -06:00
use Ecto.Schema
import Ecto.Changeset
schema "devices" do
field(:name, :string)
2017-11-10 13:10:02 -07:00
field(:timezone, :string)
2017-10-25 21:43:30 -06:00
end
@required_fields [:id, :name]
def changeset(%Device{} = device, params \\ %{}) do
2017-10-25 21:43:30 -06:00
device
|> cast(params, @required_fields)
|> validate_required(@required_fields)
|> unique_constraint(:id)
end
end