Add enigmas table / private asset
parent
b25f8526bc
commit
acf4de0671
|
@ -35,6 +35,7 @@ erl_crash.dump
|
|||
*.js
|
||||
/release-*
|
||||
/node_modules
|
||||
scratchpad.*
|
||||
|
||||
# Various env vars.
|
||||
.env
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
defmodule FarmbotCore.Asset.Private.Enigma do
|
||||
@moduledoc """
|
||||
An Enigma is essentially a merge conflict-
|
||||
it represents data that has two conflicting
|
||||
forms in two different systems (eg: API vs. Bot)
|
||||
and requires human intervention to rectify.
|
||||
"""
|
||||
alias FarmbotCore.Asset.Private.Enigma
|
||||
use Ecto.Schema
|
||||
|
||||
@behaviour FarmbotCore.Asset.View
|
||||
|
||||
schema "enigmas" do
|
||||
field(:priority, :integer)
|
||||
field(:problem_tag, :string)
|
||||
field(:created_at, :utc_datetime)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def render(%Enigma{} = data) do
|
||||
%{
|
||||
priority: data.priority,
|
||||
problem_tag: data.problem_tag,
|
||||
created_at: DateTime.to_unix(data.utc_datetime)
|
||||
}
|
||||
end
|
||||
end
|
|
@ -21,6 +21,7 @@ defmodule FarmbotCore.BotStateNG do
|
|||
field(:process_info, {:map, {:string, :any}}, default: %{farmwares: %{}})
|
||||
field(:pins, {:map, {:integer, :map}}, default: %{})
|
||||
field(:jobs, {:map, {:string, :map}}, default: %{})
|
||||
field(:enigmas, {:map, {:string, :map}}, default: %{})
|
||||
end
|
||||
|
||||
def new do
|
||||
|
@ -101,4 +102,15 @@ defmodule FarmbotCore.BotStateNG do
|
|||
|
||||
put_change(cs, :jobs, new_jobs)
|
||||
end
|
||||
|
||||
def set_enigma(state, %{uuid: uuid} = enigma) do
|
||||
cs = changeset(state, %{})
|
||||
|
||||
new_enigmas =
|
||||
cs
|
||||
|> get_field(:enigmas)
|
||||
|> Map.put(uuid, enigma)
|
||||
|
||||
put_change(cs, :enigmas, new_enigmas)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
defmodule FarmbotCore.Config.Repo.Migrations.AddEnigmasTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table("enigmas", primary_key: false) do
|
||||
add(:uuid, :binary_id, primary_key: true)
|
||||
add(:problem_tag, :string)
|
||||
add(:priority, :integer)
|
||||
add(:created_at, :utc_datetime)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue