# Major Domo Database API FastAPI backend serving SBA fantasy league data. Peewee ORM with PostgreSQL. ## Commands ```bash docker-compose up # Start PostgreSQL + API + Adminer docker-compose up --build # Rebuild and start docker-compose --profile sync up sync-prod # One-time production data sync python migrations.py # Run migrations (SQL files in migrations/) ``` - **Dev server**: `10.10.0.42` | **Adminer**: `http://10.10.0.42:8080` - **Production**: `ssh akamai` → `cd container-data/sba-database` ## Architecture - **Routers**: Domain-based in `app/routers_v3/` under `/api/v3/` prefix - **ORM**: Peewee — always specify `Meta.table_name` to match PostgreSQL naming - **Auth**: OAuth2 bearer token via `API_TOKEN` env var - **Error handling**: `@handle_db_errors` decorator (logging, rollback, HTTP errors) - **POST models**: Use `Optional[int] = None` for `id` fields (DB auto-generates) - **Logging**: Rotating file handler (`/tmp/sba-database.log`, 8MB max, 5 backups) ## Environment Variables **Required**: `API_TOKEN`, `POSTGRES_HOST`, `POSTGRES_DB`, `POSTGRES_USER`, `POSTGRES_PASSWORD` **Optional**: `POSTGRES_PORT` (5432), `LOG_LEVEL` (WARNING), `PRIVATE_IN_SCHEMA` ## Important - All active code is in `/app` — root-level `main.py`, `db_engine.py` are legacy, not in use - PostgreSQL only (no SQLite fallback) - Migrations are SQL files in `migrations/`, applied manually via psql - API docs auto-generated at `/api/docs`