Separate PokeAPI ID from national dex for correct form identification

Pokemon forms (e.g., Alolan Rattata) had their PokeAPI ID (10091) stored as
national_dex, causing them to display incorrectly. This renames the unique
identifier to pokeapi_id and adds a real national_dex field shared between
forms and their base species, so Alolan Rattata correctly shows as #19.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 14:55:06 +01:00
parent cb027e5215
commit d168d99bba
46 changed files with 23459 additions and 22289 deletions

View File

@@ -40,16 +40,18 @@ async def upsert_games(session: AsyncSession, games: list[dict]) -> dict[str, in
async def upsert_pokemon(session: AsyncSession, pokemon_list: list[dict]) -> dict[int, int]:
"""Upsert pokemon records, return {national_dex: id} mapping."""
"""Upsert pokemon records, return {pokeapi_id: id} mapping."""
for poke in pokemon_list:
stmt = insert(Pokemon).values(
pokeapi_id=poke["pokeapi_id"],
national_dex=poke["national_dex"],
name=poke["name"],
types=poke["types"],
sprite_url=poke.get("sprite_url"),
).on_conflict_do_update(
index_elements=["national_dex"],
index_elements=["pokeapi_id"],
set_={
"national_dex": poke["national_dex"],
"name": poke["name"],
"types": poke["types"],
"sprite_url": poke.get("sprite_url"),
@@ -59,8 +61,8 @@ async def upsert_pokemon(session: AsyncSession, pokemon_list: list[dict]) -> dic
await session.flush()
result = await session.execute(select(Pokemon.national_dex, Pokemon.id))
return {row.national_dex: row.id for row in result}
result = await session.execute(select(Pokemon.pokeapi_id, Pokemon.id))
return {row.pokeapi_id: row.id for row in result}
async def upsert_routes(
@@ -131,9 +133,9 @@ async def upsert_route_encounters(
"""Upsert encounters for a route, return count of upserted rows."""
count = 0
for enc in encounters:
pokemon_id = dex_to_id.get(enc["national_dex"])
pokemon_id = dex_to_id.get(enc["pokeapi_id"])
if pokemon_id is None:
print(f" Warning: no pokemon_id for dex {enc['national_dex']}")
print(f" Warning: no pokemon_id for pokeapi_id {enc['pokeapi_id']}")
continue
stmt = insert(RouteEncounter).values(
@@ -169,8 +171,8 @@ async def upsert_evolutions(
count = 0
for evo in evolutions:
from_id = dex_to_id.get(evo["from_national_dex"])
to_id = dex_to_id.get(evo["to_national_dex"])
from_id = dex_to_id.get(evo["from_pokeapi_id"])
to_id = dex_to_id.get(evo["to_pokeapi_id"])
if from_id is None or to_id is None:
continue