Phase 3 — Game.week_id foreign key #409
Labels
No labels
Kestra
bug
enhancement
someday
subtask
☁️ api
🎛️ infrastructure
🐞 sentry
📆 2025 Season
📝 pages
allpicks
📝 pages
picks
📝 pages
standings
🚀 performance
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
#406 Resolve the technical debt issues that remain for the
week table issue
johnsturgeon/tgfp-web
Reference
johnsturgeon/tgfp-web#409
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Parent: #406 · Tech debt:
Gamehas noweek_idback-pointerWhy
Weekis authoritative for what week it is, but nothing references it.Gamestill carries
season/season_type/week_noas three loose columns, so agame agrees with its week only by convention, and every week-scoped query
hand-assembles a three-column
WHERE.This gets materially harder the longer it waits.
game,playergamepick, andplayerawardare all empty in production right now, sothe column can be created NOT NULL in a single revision with no
nullable-then-backfill-then-alter dance. The first time prod holds real games,
this becomes a three-step migration against live data.
Needs Phase 1 (a
Weekrow must exist forcreate_the_picksto point at).Tasks
Game.week_idas a NOT NULL FK plus migration. One revision,no backfill, while the tables are still empty.
create_the_pickssetsweek_idvia get-or-create onWeek, thesame way it already resolves teams.
Game.games_for_weekandGame.get_first_game_of_the_weekto filter on
week_id.PlayerGamePick.find_picks_for_weekandupsert_award_with_argsto the FK. Keep this separate from the taskabove — different tables, different blast radius.
Game.current_season_distinct_week_infosqueriesweekdirectly.TheDISTINCTovergamedisappears entirely.Moved to #414, which is the same change described twice. Do it
there — it also has to move the method onto
Week, and it depends onodds_stateexisting, which this issue does not.Watch out
If week rows exist for weeks that have no games yet, the week picker willrender links to empty pages. Filter ongame_state != PENDING— that is whatthe Phase 2 column is for, and it is why no separatepicks_created_atcolumnis needed.If week rows exist for weeks whose picks page has not been released, the week
picker will render links to pages nobody should see yet. Filter on
odds_state == LOCKED.The struck version had this backwards, and the reasoning is worth keeping
visible because it is the same mistake that shaped
create_the_picks:game_state != PENDINGasks "do game rows exist", when the question is "isthis week viewable". Those coincide today only because the picks page is a
side effect of rows being inserted — which is the accident this epic is
unwinding, not a property to build on.
odds_stateis the released flag, andit is why a separate
picks_created_atcolumn is still not needed.The
DISTINCTovergameis currently serving as this filter by accident,which is why nothing has gone wrong yet. Removing it (in #414) without
odds_statein place is what would break the picker.Done when
game.week_idis NOT NULL with no orphans.app/modelsfilters on theseason/season_type/week_notriple to identify a week.
The week picker renders fromThe week picker renders fromweekalone.weekalone, filtered onodds_state == LOCKED— see #414.weektable issueweektable issue #406current_season_distinct_week_infosto the 'week' model #414gamemodel as a foreign key #418