Daedalus and Talos integration test
This commit is contained in:
1470
backend/src/app/seeds/data/abilities.json
Normal file
1470
backend/src/app/seeds/data/abilities.json
Normal file
File diff suppressed because it is too large
Load Diff
4687
backend/src/app/seeds/data/moves.json
Normal file
4687
backend/src/app/seeds/data/moves.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,11 +4,13 @@ from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.ability import Ability
|
||||
from app.models.boss_battle import BossBattle
|
||||
from app.models.boss_pokemon import BossPokemon
|
||||
from app.models.encounter import Encounter
|
||||
from app.models.evolution import Evolution
|
||||
from app.models.game import Game
|
||||
from app.models.move import Move
|
||||
from app.models.pokemon import Pokemon
|
||||
from app.models.route import Route
|
||||
from app.models.route_encounter import RouteEncounter
|
||||
@@ -484,3 +486,59 @@ async def upsert_evolutions(
|
||||
|
||||
await session.flush()
|
||||
return count
|
||||
|
||||
|
||||
async def upsert_moves(
|
||||
session: AsyncSession,
|
||||
moves: list[dict],
|
||||
) -> int:
|
||||
"""Upsert move records, return count of upserted rows."""
|
||||
count = 0
|
||||
for move in moves:
|
||||
stmt = (
|
||||
insert(Move)
|
||||
.values(
|
||||
name=move["name"],
|
||||
introduced_gen=move["introduced_gen"],
|
||||
type=move.get("type"),
|
||||
)
|
||||
.on_conflict_do_update(
|
||||
index_elements=["name"],
|
||||
set_={
|
||||
"introduced_gen": move["introduced_gen"],
|
||||
"type": move.get("type"),
|
||||
},
|
||||
)
|
||||
)
|
||||
await session.execute(stmt)
|
||||
count += 1
|
||||
|
||||
await session.flush()
|
||||
return count
|
||||
|
||||
|
||||
async def upsert_abilities(
|
||||
session: AsyncSession,
|
||||
abilities: list[dict],
|
||||
) -> int:
|
||||
"""Upsert ability records, return count of upserted rows."""
|
||||
count = 0
|
||||
for ability in abilities:
|
||||
stmt = (
|
||||
insert(Ability)
|
||||
.values(
|
||||
name=ability["name"],
|
||||
introduced_gen=ability["introduced_gen"],
|
||||
)
|
||||
.on_conflict_do_update(
|
||||
index_elements=["name"],
|
||||
set_={
|
||||
"introduced_gen": ability["introduced_gen"],
|
||||
},
|
||||
)
|
||||
)
|
||||
await session.execute(stmt)
|
||||
count += 1
|
||||
|
||||
await session.flush()
|
||||
return count
|
||||
|
||||
@@ -10,18 +10,22 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.core.database import async_session
|
||||
from app.models.ability import Ability
|
||||
from app.models.boss_battle import BossBattle
|
||||
from app.models.boss_pokemon import BossPokemon
|
||||
from app.models.evolution import Evolution
|
||||
from app.models.game import Game
|
||||
from app.models.move import Move
|
||||
from app.models.pokemon import Pokemon
|
||||
from app.models.route import Route
|
||||
from app.models.route_encounter import RouteEncounter
|
||||
from app.models.version_group import VersionGroup
|
||||
from app.seeds.loader import (
|
||||
upsert_abilities,
|
||||
upsert_bosses,
|
||||
upsert_evolutions,
|
||||
upsert_games,
|
||||
upsert_moves,
|
||||
upsert_pokemon,
|
||||
upsert_route_encounters,
|
||||
upsert_routes,
|
||||
@@ -69,6 +73,24 @@ async def seed(*, prune: bool = False):
|
||||
dex_to_id = await upsert_pokemon(session, pokemon_data)
|
||||
print(f"Pokemon: {len(dex_to_id)} upserted")
|
||||
|
||||
# 3a. Upsert Moves
|
||||
moves_path = DATA_DIR / "moves.json"
|
||||
if moves_path.exists():
|
||||
moves_data = load_json("moves.json")
|
||||
moves_count = await upsert_moves(session, moves_data)
|
||||
print(f"Moves: {moves_count} upserted")
|
||||
else:
|
||||
print("No moves.json found, skipping moves")
|
||||
|
||||
# 3b. Upsert Abilities
|
||||
abilities_path = DATA_DIR / "abilities.json"
|
||||
if abilities_path.exists():
|
||||
abilities_data = load_json("abilities.json")
|
||||
abilities_count = await upsert_abilities(session, abilities_data)
|
||||
print(f"Abilities: {abilities_count} upserted")
|
||||
else:
|
||||
print("No abilities.json found, skipping abilities")
|
||||
|
||||
# 4. Per version group: upsert routes once, then encounters per game
|
||||
total_routes = 0
|
||||
total_encounters = 0
|
||||
@@ -199,6 +221,10 @@ async def verify():
|
||||
vg_count = (await session.execute(select(func.count(VersionGroup.id)))).scalar()
|
||||
games_count = (await session.execute(select(func.count(Game.id)))).scalar()
|
||||
pokemon_count = (await session.execute(select(func.count(Pokemon.id)))).scalar()
|
||||
moves_count = (await session.execute(select(func.count(Move.id)))).scalar()
|
||||
abilities_count = (
|
||||
await session.execute(select(func.count(Ability.id)))
|
||||
).scalar()
|
||||
routes_count = (await session.execute(select(func.count(Route.id)))).scalar()
|
||||
enc_count = (
|
||||
await session.execute(select(func.count(RouteEncounter.id)))
|
||||
@@ -208,6 +234,8 @@ async def verify():
|
||||
print(f"Version Groups: {vg_count}")
|
||||
print(f"Games: {games_count}")
|
||||
print(f"Pokemon: {pokemon_count}")
|
||||
print(f"Moves: {moves_count}")
|
||||
print(f"Abilities: {abilities_count}")
|
||||
print(f"Routes: {routes_count}")
|
||||
print(f"Route Encounters: {enc_count}")
|
||||
print(f"Boss Battles: {boss_count}")
|
||||
|
||||
Reference in New Issue
Block a user