paper-dynasty-database/CLAUDE.md
Cal Corum 3104ed3b00 fix: remove legacy SQLite compatibility code (#122)
Closes #122

Both prod and dev environments use PostgreSQL. Removes all SQLite
compatibility code that was never exercised in practice.

Changes:
- db_engine.py: replace SQLite/PostgreSQL branching with direct
  PooledPostgresqlDatabase init; remove DATABASE_TYPE, SKIP_TABLE_CREATION,
  all db.create_tables() calls, and commented-out SQLite scout_db code
- db_helpers.py: remove DATABASE_TYPE var and SQLite on_conflict_replace
  branch from upsert_many(); PostgreSQL ON CONFLICT is now the only path
- players.py: update stale comment
- tests/conftest.py: remove DATABASE_TYPE env var (no longer needed);
  keep POSTGRES_PASSWORD dummy for instantiation
- CLAUDE.md: update SQLite references to PostgreSQL

Note: unit tests in test_evolution_seed.py and test_season_stats_model.py
use SqliteDatabase(':memory:') for test isolation — this is legitimate test
infrastructure, not production SQLite compatibility code.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 16:33:27 -05:00

2.5 KiB

Paper Dynasty Database API

FastAPI backend for baseball card game data. Peewee ORM with PostgreSQL.

Commands

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000  # Dev server
python main.py                                              # Alt start
python db_migrations.py                                     # Run migrations
docker build -t paper-dynasty-db .                          # Build image

Architecture

  • Routers: Domain-based in app/routers_v2/ (cards, players, teams, packs, stats, gauntlets, scouting)
  • ORM: Peewee with PostgreSQL (pd_master database via PooledPostgresqlDatabase)
  • Card images: Playwright/Chromium renders HTML templates → screenshots (see routers_v2/players.py)
  • Logging: Rotating files in logs/database/{date}.log

Key Constants

  • LIVE_CARDSET_ID: 24 (current active cardset, in db_engine.py)
  • ranked_cardsets: Legal cardsets for ranked play
  • CARDSETS: Configuration for game modes and card availability

Environments & Troubleshooting

Dev Prod
URL pddev.manticorum.com pd.manticorum.com
Host ssh pd-database ssh akamai/root/container-data/paper-dynasty
API container dev_pd_database pd_api
PostgreSQL sba_postgres / paperdynasty_dev / sba_admin pd_postgres / pd_master
Adminer port 8081
API port 816 815
Image manticorum67/paper-dynasty-database manticorum67/paper-dynasty-database

Logs

  • Container logs: docker logs --since 1h pd_api
  • Log file (in container): logs/database/YYYY-MM-DD.log (date-stamped daily, no rotation)
  • API docs: /api/docs and /api/redoc

Key Env Vars

API_TOKEN, LOG_LEVEL, POSTGRES_HOST, POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD

Common Issues

  • 502 Bad Gateway → API container crashed; check docker logs pd_api
  • Card image generation failures → Playwright/Chromium issue; check for missing dependencies
  • DB connection errors → verify POSTGRES_HOST points to correct container name
  • CI/CD: Gitea Actions on CalVer tag push — builds Docker image and pushes to Docker Hub
  • Release: git tag YYYY.M.BUILD && git push origin YYYY.M.BUILD → CI builds + pushes image + notifies Discord

Important

  • Docker image installs only Playwright Chromium (not all browsers) to optimize size
  • Teams have dynamic card pricing based on market activity
  • Supports both human players and AI teams
  • Gauntlet events use special reward structures and card pools