# 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:814` / `ssh sba-db` → `cd container-data/dev-sba-database` | **Adminer**: `http://10.10.0.42:8080` - **Production**: `ssh akamai` → `cd container-data/sba-database` - **Deploy (dev/prod)**: `docker-compose pull && docker-compose down && docker-compose up -d` (on the remote server) ## 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) ## Production Environment - **Host**: `ssh akamai` - **Path**: `~/container-data/sba-database` - **Bot container**: `sba_postgres` (PostgreSQL) + `sba_db_api` (API) — check with `docker ps` - **Other services on same host**: `major-domo-discord-app-1`, `sba_adminer`, `sba-website_sba-web_1`, `sba-ghost_sba-ghost_1` - **Image**: `manticorum67/major-domo-database` (Docker Hub) - **Version file**: `VERSION` — bump before merge to `main` - **Health**: API Port 80 — `/health`, `/ready`, `/metrics`, `/diagnostics` - **Env vars**: Set in `docker-compose.prod.yml` and passed to the container on startup (not stored in GitHub) ## Development Environment - **Host**: `ssh sba-db` - **Path**: `~/container-data/dev-sba-database` - **Bot container**: `dev_sba_postgres` (PostgreSQL) + `dev_sba_db_api` (API) — check with `docker ps` - **Image**: `manticorum67/major-domo-database:dev` (Docker Hub) - **CI/CD**: Gitea Actions on PR to `main` — builds Docker image, auto-generates CalVer version (`YYYY.MM.BUILD`) on merge ## 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` - **NEVER run or test against the local docker compose** — always deploy to and test against the dev server (`10.10.0.42:814`). The local container has no meaningful data.