fix: join through player_teams instead of non-existent players.team_id #26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "25-bug-queries-reference-players-team-id-bu"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
column p.team_id does not existplayers.team_idin favor ofplayer_teamsjoin table (Mar 25)Changes
src/routes/contract/[token]/+page.server.ts: join throughplayer_teams ptthenteams t ON t.id = pt.team_idsrc/routes/contract/[token]/sign/+server.ts: same join pattern, aliased columns withp.andpt.prefixesTest Plan
/contract/{token}loads without 500/contract/{token}/signPOST succeedsteam_idReview Checklist
Related Notes
forgejo_admin/westside-contracts #25— the Forgejo issue this PR fixesproject-westside-basketball— the project this work belongs toCloses #25
PR #26 Review
DOMAIN REVIEW
Tech stack: SvelteKit (adapter-node), TypeScript, raw SQL via
pgPool, direct Postgres queries.SQL correctness:
The fix correctly replaces
LEFT JOIN teams t ON t.id = p.team_idwith the two-hop join throughplayer_teams:This matches the basketball-api migration 019 which dropped
players.team_idin favor of theplayer_teamsjunction table (composite PK onplayer_id, team_id).Both changed files are correct:
+page.server.ts: TheSELECT p.*no longer includesteam_id(column dropped), but the return object only usesteam_namefrom the teams join -- correct.+server.ts: Explicitly selectspt.team_idwhich maps toplayer.team_idfor the downstream team lookup (line 58-60) and outbox payload (line 100) -- correct.Many-to-many row duplication concern (non-blocking):
The
player_teamstable is many-to-many (composite PK). If a player belongs to multiple teams, these LEFT JOINs will produce multiple rows androws[0]will silently pick an arbitrary team. This is a pre-existing architectural concern (the oldp.team_idwas 1:1), but the new join surface makes it possible. In practice, westside players are assigned to one team, so the risk is low. ALIMIT 1orDISTINCT ONwould be defensive but is out of scope for this bug fix.TypeScript types:
Playerinterface (src/lib/types.tsline 5) still declaresteam_id: number | null. This remains correct sincept.team_idis aliased asteam_idin the sign endpoint query result.BLOCKERS
None.
This is a 2-file, 6-line fix to a cross-repo regression (basketball-api migration 019 broke westside-contracts queries). The SQL changes are minimal, correct, and tightly scoped. No new functionality is introduced -- this restores existing functionality that broke due to a schema migration in another repo.
On test coverage: The repo has 12 existing tests in
tests/validation.test.tscovering input validation. This PR changes raw SQL join clauses, which cannot be meaningfully unit-tested without a database. The Test Plan in the PR body specifies manual integration verification (load contract page, POST sign, verify outbox payload). For a hotfix restoring broken production functionality, this is acceptable -- there is no new feature surface to cover.NITS
Defensive query for multi-team players (
+page.server.ts:15-16,+server.ts:13-14): Consider addingLIMIT 1to both queries or usingDISTINCT ON (p.id)to guard against future multi-team assignments returning duplicate rows. Not required for this fix, but worth a follow-up ticket.Playerinterface still hasteam_id(src/lib/types.ts:5): Theteam_idfield on thePlayerinterface technically no longer lives on theplayerstable -- it comes from the join. This is semantically misleading but functionally correct since the query aliasespt.team_idtoteam_id. Consider a comment or renaming in a future cleanup.SOP COMPLIANCE
25-bug-queries-reference-players-team-id-bureferences issue #25project-westside-basketball) -- no plan slug required (bug fix, not plan work)fix: join through player_teams instead of non-existent players.team_id)Closes #25links PR to parent issuePROCESS OBSERVATIONS
players.team_idwithout updating westside-contracts, which was scaffolded Mar 24 when the column still existed. This is a classic cross-repo schema coupling problem. Consider adding a "downstream consumers" checklist to migration PRs in basketball-api, or a CI smoke test that validates westside-contracts queries against the current schema.VERDICT: APPROVED