Skip to content

feat(harmonia-db): play history, scrobble tracking, and listening analytics (P2-14)#45

Merged
forkwright merged 1 commit intomainfrom
p2-14/play-history
Mar 12, 2026
Merged

feat(harmonia-db): play history, scrobble tracking, and listening analytics (P2-14)#45
forkwright merged 1 commit intomainfrom
p2-14/play-history

Conversation

@forkwright
Copy link
Owner

Summary

  • Migration 002_play_history.sql: four new tables — play_sessions (one row per contiguous playback), play_stats_daily (pre-computed daily aggregates), play_stats_item (per-item lifetime stats), play_streaks (consecutive-day tracking) — with indexes for common query patterns
  • SessionId newtype added to harmonia-common/ids.rs (UUIDv7, "sess-" prefix)
  • NowPlayingStarted / PlaybackSessionEnded variants added to HarmoniaEvent with serde roundtrip tests
  • crates/harmonia-db/src/repo/play_history.rs: full repository module — session lifecycle, scrobble queue, incremental stats upserts, analytics queries (top_items, listening_time, daily_activity, on_this_day), streak tracking, and discovery helpers (never_played, not_played_since)

Test plan

  • cargo check -p harmonia-db -p harmonia-common — clean
  • cargo test -p harmonia-db -p harmonia-common — 56 tests pass (20 new in play_history)
  • cargo clippy -p harmonia-db -p harmonia-common -- -D warnings — clean
  • cargo fmt --all — no diff

Covers all scenarios from the spec: session lifecycle, scrobble eligibility and submission, stats aggregation (play count, skip count, first/last played, daily upserts), analytics queries, streak create/extend/gap logic, event serde.

…lytics (P2-14)

- Migration 002_play_history.sql: play_sessions, play_stats_daily,
  play_stats_item, play_streaks tables with appropriate indexes
- harmonia-common: SessionId newtype (UUIDv7, "sess-" prefix)
- harmonia-common/aggelia: NowPlayingStarted and PlaybackSessionEnded
  event variants with serde roundtrip tests
- harmonia-db/repo/play_history: session lifecycle, scrobble queue,
  incremental stats aggregation, analytics queries (top_items,
  listening_time, daily_activity, on_this_day, streak tracking),
  and discovery helpers (never_played, not_played_since)
- 20 tests covering all specified scenarios
@forkwright forkwright merged commit 88f0e93 into main Mar 12, 2026
1 check passed
@forkwright forkwright deleted the p2-14/play-history branch March 13, 2026 14:05
This was referenced Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant