--- # nuzlocke-tracker-vmto title: 'Backend: Journal entries model, API, and migration' status: completed type: task priority: normal tags: - failed created_at: 2026-03-20T15:15:48Z updated_at: 2026-03-20T15:30:47Z parent: nuzlocke-tracker-mz16 --- Create the backend infrastructure for session journal entries. ## Data Model `journal_entries` table: - `id` (UUID, PK) - `run_id` (FK to runs) - `boss_result_id` (FK to boss_results, nullable) — optional link to a boss battle - `title` (str, required) - `body` (text, required) — raw markdown content - `created_at`, `updated_at` (timestamps) ## Checklist - [x] Create Alembic migration for `journal_entries` table - [x] Create `JournalEntry` SQLAlchemy model with relationships to `Run` and `BossResult` - [x] Create Pydantic schemas (`JournalEntryCreate`, `JournalEntryUpdate`, `JournalEntryResponse`) - [x] Create CRUD operations for journal entries - [x] Create API endpoints under `/runs/{run_id}/journal`: - `GET /` — list entries for a run (ordered by created_at desc) - `POST /` — create entry - `GET /{entry_id}` — get single entry - `PUT /{entry_id}` — update entry - `DELETE /{entry_id}` — delete entry - [x] Add optional `boss_result_id` query filter to GET list endpoint ## Summary of Changes Implemented backend infrastructure for session journal entries: **Files created:** - `backend/src/app/alembic/versions/k2f3a4b5c6d7_add_journal_entries_table.py` - Migration creating `journal_entries` table with UUID PK, foreign keys to `nuzlocke_runs` and `boss_results`, and timestamp columns - `backend/src/app/models/journal_entry.py` - SQLAlchemy model with relationships to `NuzlockeRun` and `BossResult` - `backend/src/app/schemas/journal_entry.py` - Pydantic schemas for create, update, and response - `backend/src/app/api/journal_entries.py` - API endpoints for CRUD operations **Files modified:** - `backend/src/app/models/nuzlocke_run.py` - Added `journal_entries` relationship - `backend/src/app/models/__init__.py` - Exported `JournalEntry` - `backend/src/app/schemas/__init__.py` - Exported journal entry schemas - `backend/src/app/api/routes.py` - Registered journal entries router **API Endpoints:** - `GET /runs/{run_id}/journal` - List entries (supports `boss_result_id` filter) - `POST /runs/{run_id}/journal` - Create entry - `GET /runs/{run_id}/journal/{entry_id}` - Get single entry - `PUT /runs/{run_id}/journal/{entry_id}` - Update entry - `DELETE /runs/{run_id}/journal/{entry_id}` - Delete entry