strat-gameplay-webapp/backend
Cal Corum dc9f98ad88 CLAUDE: Fix batting order recovery after inning changes
When recovering game state after reconnect/refresh, the old code:
1. Only looked at the last play overall (regardless of team)
2. Used that play's batting order for the currently batting team
3. Reset the non-batting team's index to 0

This caused the wrong batter to appear after inning changes - e.g.,
batter #1 showing instead of #5 in top of 2nd after bottom of 1st ended.

Fix: Now recovers each team's batter index separately by filtering
plays by half ("top" = away team, "bottom" = home team) and finding
each team's last at-bat independently.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 23:38:54 -06:00
..
.claude CLAUDE: Add configurable regulation_innings and outs_per_inning 2025-11-19 20:06:57 -06:00
.git-hooks CLAUDE: Fix all unit test failures and implement 100% test requirement 2025-11-04 19:35:21 -06:00
alembic CLAUDE: Add Alembic migrations and database session injection 2025-11-28 12:09:09 -06:00
app CLAUDE: Fix batting order recovery after inning changes 2025-11-28 23:38:54 -06:00
scripts CLAUDE: Add test game creation utilities 2025-11-19 16:30:29 -06:00
terminal_client CLAUDE: Fix RunnerAdvancementData tuple unpacking regression 2025-11-28 23:11:26 -06:00
tests CLAUDE: Load play history on mid-game join via game_state_sync 2025-11-28 12:38:56 -06:00
.dockerignore CLAUDE: Fix Docker build for UV migration 2025-11-04 09:19:30 -06:00
.env.example CLAUDE: Implement server-side OAuth flow with HttpOnly cookies 2025-11-26 22:16:30 -06:00
.gitignore CLAUDE: Add pages/ to backend gitignore 2025-11-20 23:57:25 -06:00
.python-version CLAUDE: Migrate backend to UV package management 2025-11-04 08:52:11 -06:00
alembic.ini CLAUDE: Add Alembic migrations and database session injection 2025-11-28 12:09:09 -06:00
CLAUDE.md CLAUDE: Update documentation across codebase 2025-11-28 12:10:10 -06:00
clean_test_data.py CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
docker-compose.yml CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
Dockerfile CLAUDE: Fix Docker build for UV migration 2025-11-04 09:19:30 -06:00
mypy.ini CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00
pyproject.toml CLAUDE: Replace black and flake8 with ruff for formatting and linting 2025-11-20 15:33:21 -06:00
pyrightconfig.json Clean up false positive Pylance errors 2025-10-23 09:10:41 -05:00
pytest.ini CLAUDE: Complete Week 4 - State Management & Persistence 2025-10-22 12:01:03 -05:00
README.md CLAUDE: Update documentation across codebase 2025-11-28 12:10:10 -06:00
requirements-dev.txt CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
requirements.txt CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
TEST_COVERAGE_SUMMARY.md CLAUDE: Phase 2 test infrastructure + comprehensive documentation 2025-11-05 12:39:32 -06:00
test_db_playground.py Add scripts to test models in dev database 2025-10-23 09:10:55 -05:00
test_pd_api_live.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
test_pd_api_mock.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
test_redis_cache.py CLAUDE: Phase 3E-Final - Redis Caching & X-Check WebSocket Integration 2025-11-03 22:46:59 -06:00
uv.lock CLAUDE: Replace black and flake8 with ruff for formatting and linting 2025-11-20 15:33:21 -06:00

Paper Dynasty Backend

FastAPI-based real-time baseball game engine with WebSocket support.

Quick Start

# Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync

# Apply database migrations
uv run alembic upgrade head

# Run server
uv run python -m app.main

Database Migrations

This project uses Alembic for database schema migrations.

Initial Setup (New Database)

# Apply all migrations to create schema
uv run alembic upgrade head

Creating New Migrations

# Auto-generate from model changes
uv run alembic revision --autogenerate -m "Description of changes"

# IMPORTANT: Always review the generated migration before applying!
# Then apply:
uv run alembic upgrade head

Viewing Migration Status

# Show migration history
uv run alembic history

# Show current revision
uv run alembic current

Rolling Back

# Rollback one migration
uv run alembic downgrade -1

# Rollback to specific revision
uv run alembic downgrade 001

# Rollback all (dangerous!)
uv run alembic downgrade base

Migration Best Practices

  1. Always review auto-generated migrations before applying - autogenerate is helpful but not perfect
  2. Test migrations on dev/staging before production
  3. Keep migrations small and focused - easier to rollback
  4. Never edit migrations that have been applied to shared databases
  5. Include both upgrade and downgrade for reversibility

Existing Migrations

Revision Description
001 Initial schema (games, plays, lineups, rolls, etc.)
004 Materialized views for statistics

Documentation

See CLAUDE.md for full documentation.