mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Player-facing endgame links now use a 10-character Crockford base32 public code instead of the database UUID; admin routes keep the UUID. Existing rows are backfilled by migration, and the admin Show page displays and copies the code. The admin endgame index gains its own search box: exact database id, exact public code, or a FEN / FEN fragment. A single match opens the endgame; multiple matches list below; nothing found says so. Closes #44 Closes #45
59 lines
1.5 KiB
Elixir
59 lines
1.5 KiB
Elixir
# Script for populating the database. You can run it as:
|
|
#
|
|
# mix run priv/repo/seeds.exs
|
|
#
|
|
# Inside the script, you can read and write to any of your
|
|
# repositories directly:
|
|
#
|
|
# Chesstrainer.Repo.insert!(%Chesstrainer.SomeSchema{})
|
|
#
|
|
# We recommend using the bang functions (`insert!`, `update!`
|
|
# and so on) as they will fail if something goes wrong.
|
|
|
|
Code.require_file("seeds/endgames.ex", __DIR__)
|
|
Code.require_file("seeds/themes.ex", __DIR__)
|
|
|
|
alias Chesstrainer.Repo
|
|
alias Chesstrainer.Endgames.Endgame
|
|
alias Chesstrainer.Themes.Theme
|
|
alias Chesstrainer.Repo.Seeds.Endgames
|
|
alias Chesstrainer.Repo.Seeds.Themes
|
|
|
|
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
|
|
|
IO.puts("🌱 Seeding basic endgames into DB...")
|
|
|
|
endgames = Endgames.all()
|
|
|
|
Repo.insert_all(
|
|
Endgame,
|
|
Enum.map(endgames, fn endgame ->
|
|
fen = Chesstrainer.FEN.normalize(endgame.fen)
|
|
{:ok, key} = Chesstrainer.Key.from_fen(fen)
|
|
|
|
endgame
|
|
|> Map.put(:fen, fen)
|
|
|> Map.put(:id, Ecto.UUID.generate())
|
|
|> Map.put(:public_code, Endgame.generate_public_code())
|
|
|> Map.put(:key, key)
|
|
|> Map.merge(%{inserted_at: now, updated_at: now})
|
|
end),
|
|
on_conflict: :nothing
|
|
)
|
|
|
|
IO.puts("✅ Done seeding endgames.")
|
|
|
|
IO.puts("🌱 Seeding endgame themes into DB...")
|
|
|
|
theme_names = Themes.all()
|
|
|
|
Repo.insert_all(
|
|
Theme,
|
|
Enum.map(theme_names, fn name ->
|
|
%{name: name, category: :endgame, inserted_at: now, updated_at: now}
|
|
end),
|
|
on_conflict: :nothing
|
|
)
|
|
|
|
IO.puts("✅ Done seeding endgame themes.")
|