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
@@ -1,14 +1,14 @@
defmodule Chesstrainer.Repo.Migrations.CreateTags do
defmodule Chesstrainer.Repo.Migrations.CreateThemes do
use Ecto.Migration
def change do
create table(:tags) do
create table(:themes) do
add :name, :string
add :category, :string
timestamps(type: :utc_datetime)
end
create unique_index(:tags, [:name, :category])
create unique_index(:themes, [:name, :category])
end
end
@@ -1,12 +0,0 @@
defmodule Chesstrainer.Repo.Migrations.CreateEndgamesTags do
use Ecto.Migration
def change do
create table(:endgames_tags, primary_key: false) do
add :endgame_id, references(:endgames, type: :binary_id, on_delete: :delete_all)
add :tag_id, references(:tags, on_delete: :delete_all)
end
create unique_index(:endgames_tags, [:endgame_id, :tag_id])
end
end
@@ -0,0 +1,12 @@
defmodule Chesstrainer.Repo.Migrations.CreateEndgamesThemes do
use Ecto.Migration
def change do
create table(:endgames_themes, primary_key: false) do
add :endgame_id, references(:endgames, type: :binary_id, on_delete: :delete_all)
add :theme_id, references(:themes, on_delete: :delete_all)
end
create unique_index(:endgames_themes, [:endgame_id, :theme_id])
end
end
@@ -1,15 +0,0 @@
defmodule Chesstrainer.Repo.Migrations.CaseInsensitiveTagNames do
use Ecto.Migration
def up do
drop index(:tags, [:name, :category])
create unique_index(:tags, ["lower(name)", :category], name: :tags_name_category_lower_index)
end
def down do
drop index(:tags, ["lower(name)", :category], name: :tags_name_category_lower_index)
create unique_index(:tags, [:name, :category])
end
end
@@ -0,0 +1,17 @@
defmodule Chesstrainer.Repo.Migrations.CaseInsensitiveThemeNames do
use Ecto.Migration
def up do
drop index(:themes, [:name, :category])
create unique_index(:themes, ["lower(name)", :category],
name: :themes_name_category_lower_index
)
end
def down do
drop index(:themes, ["lower(name)", :category], name: :themes_name_category_lower_index)
create unique_index(:themes, [:name, :category])
end
end