paper-dynasty-database/app/seed/evolution_tracks.py
Cal Corum 25f04892c2 feat: evolution track seed data and tests (WP-03) (#68)
Closes #68

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 17:35:12 -05:00

42 lines
1.3 KiB
Python

"""Seed data fixture for EvolutionTrack.
Inserts the three universal evolution tracks (Batter, Starting Pitcher,
Relief Pitcher) if they do not already exist. Safe to call multiple times
thanks to get_or_create — depends on WP-01 (EvolutionTrack model) to run.
"""
import json
import os
_JSON_PATH = os.path.join(os.path.dirname(__file__), "evolution_tracks.json")
def load_tracks():
"""Return the locked list of evolution track dicts from the JSON fixture."""
with open(_JSON_PATH) as fh:
return json.load(fh)
def seed(model_class=None):
"""Insert evolution tracks that are not yet in the database.
Args:
model_class: Peewee model with get_or_create support. Defaults to
``app.db_engine.EvolutionTrack`` (imported lazily so this module
can be imported before WP-01 lands).
Returns:
List of (instance, created) tuples from get_or_create.
"""
if model_class is None:
from app.db_engine import EvolutionTrack as model_class # noqa: PLC0415
results = []
for track in load_tracks():
instance, created = model_class.get_or_create(
card_type=track["card_type"],
defaults=track,
)
results.append((instance, created))
return results