# Historical Backfill (--init) Feature ## Task Add CLI-based historical show backfill with episode numbering throughout the system. ## Changes Made ### New file - `src/ntr_fetcher/backfill.py` — Computes show weeks from an anchor episode/date, batch-fetches all likes from SoundCloud, partitions them into weekly buckets, and populates the DB. ### Modified files - `src/ntr_fetcher/models.py` — Added `episode_number: int | None` to `Show` dataclass. - `src/ntr_fetcher/db.py` — Added `episode_number` column to schema, ALTER TABLE migration for existing DBs, updated `get_or_create_show` to accept/store episode numbers, added `get_latest_episode_number()` and `update_show_episode_number()`, changed `list_shows` ordering to `week_start DESC`. - `src/ntr_fetcher/main.py` — Added `argparse` with `--init`, `--show`, `--aired` flags. `--init` runs backfill then exits; default starts the server as before. - `src/ntr_fetcher/poller.py` — Auto-assigns episode number (latest + 1) when creating a new show if historical data exists. - `src/ntr_fetcher/api.py` — Added `episode_number` to `/playlist`, `/shows`, `/shows/{show_id}` responses. ### New/updated tests - `tests/test_backfill.py` — Week computation, batch partitioning, empty data, idempotency. - `tests/test_db.py` — Episode number creation, update, and `get_latest_episode_number`. - `tests/test_poller.py` — Auto-numbering when history exists, skips when no history, skips when already assigned. - `tests/test_api.py` — `episode_number` present in show responses. ## Results - 58 tests passing (up from 42), ruff clean. ## Usage ``` NTR_ADMIN_TOKEN=token ntr-fetcher --init --show 521 --aired 2026-01-07 ```