Statcast: role belongs in the key (two-way players)

Found by inducing the real job on the server, not by review: the first chunk
wrote, the second failed with 'ON CONFLICT DO UPDATE command cannot affect row
a second time'. A player can legitimately appear in BOTH the batter and the
pitcher feeds — two-way players, position players who pitch, pitchers who bat —
so (sport, season, source_id) collapsed two real profiles into one key and a
single batch hit the same row twice.

Ohtani has a real batter profile and a real pitcher profile. Merging them would
invent one player out of two genuinely different sets of measurements, so role
goes in the primary key rather than one profile winning. Migration 031 applied;
conflict target updated; a two-way case is now a test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCNgGSt5qvcLxaeQqa7Zpj
This commit is contained in:
Kev
2026-07-20 21:49:53 -04:00
parent 528cb1a6d0
commit a011ae79fe
3 changed files with 22 additions and 3 deletions
@@ -60,7 +60,9 @@ create table if not exists statcast_aggregates (
updated_at timestamptz not null default now(),
source text not null default 'baseball_savant',
primary key (sport, season, source_id)
-- ROLE is in the key: two-way players have a real batter profile AND a
-- real pitcher profile (see migration 031).
primary key (sport, season, source_id, role)
);
create index if not exists statcast_agg_player_key_idx on statcast_aggregates (sport, season, player_key);