Rename Tag to Theme across code and schema

Rename the endgame-label concept from Tag to Theme to match the glossary:
the context becomes Chesstrainer.Themes, the schema Chesstrainer.Themes.Theme,
and the Endgame association is :themes. The category enum
(endgame/opening/tactic) is preserved.

Rewrite the original migrations in place so themes / endgames_themes
(with theme_id) are created directly, instead of adding a transition
migration.

Closes #12
This commit is contained in:
2026-11-02 09:14:17 +01:00
parent 645f65f2a3
commit cd2e7f0164
21 changed files with 387 additions and 382 deletions
+27
View File
@@ -0,0 +1,27 @@
defmodule Chesstrainer.Themes.Theme do
use Ecto.Schema
import Ecto.Changeset
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