Files
chess-endgame-trainer/lib/chesstrainer/themes/theme.ex
T
owenrees fddb94e2bd Add admin bulk FEN importer (#156)
* change position of theme picker

* Add admin bulk FEN importer

Paste FENs, resolve results from the local Syzygy tablebase only, preview each line's status, and bulk insert with themes and a batch rating.
2026-11-12 22:44:13 +01:00

30 lines
725 B
Elixir

defmodule Chesstrainer.Themes.Theme do
use Ecto.Schema
import Ecto.Changeset
@type t :: %__MODULE__{}
schema "themes" do
field :name, :string
field :category, Ecto.Enum, values: [endgame: "endgame", opening: "opening", tactic: "tactic"]
timestamps(type: :utc_datetime)
end
@doc false
def changeset(theme, attrs) do
theme
|> cast(attrs, [:name, :category])
|> update_change(:name, fn
name when is_binary(name) -> String.trim(name)
name -> name
end)
|> validate_required([:name, :category])
|> validate_length(:name, min: 1, max: 60)
|> unique_constraint(:name,
name: :themes_name_category_lower_index,
message: "already exists"
)
end
end