Refactor Roster model from 26 FK columns to a junction table #29

Closed
opened 2026-02-20 06:53:48 +00:00 by cal · 1 comment
Owner

`app/db_engine.py:497-543`. `Roster` stores lineup slots as `card_1` through `card_26` as individual foreign key columns. Makes it impossible to query "which rosters contain card X" efficiently. Consider a standard junction table `(roster_id, slot, card_id)`.

Priority: low

\`app/db_engine.py:497-543\`. \`Roster\` stores lineup slots as \`card_1\` through \`card_26\` as individual foreign key columns. Makes it impossible to query "which rosters contain card X" efficiently. Consider a standard junction table \`(roster_id, slot, card_id)\`. **Priority**: low
cal added the
tech-debt
performance
labels 2026-02-20 06:53:48 +00:00
cal added the
ai-working
label 2026-03-04 15:31:02 +00:00
cal removed the
ai-working
label 2026-03-04 15:33:39 +00:00
Author
Owner

PR #58 opened: #58

Approach: Added a RosterSlot junction table (roster, slot, card) with a unique index on (roster, slot). Removed the 26 FK columns from the Roster ORM model and replaced the commented-out get_cards() stub with a working implementation that JOINs through RosterSlot.

A migration script at migrations/migrate_roster_junction_table.py reads the legacy card_N_id columns via raw SQL and backfills the new table. The legacy columns remain in the DB schema until an operator drops them after verifying the migration.

PR #58 opened: https://git.manticorum.com/cal/paper-dynasty-database/pulls/58 **Approach:** Added a `RosterSlot` junction table `(roster, slot, card)` with a unique index on `(roster, slot)`. Removed the 26 FK columns from the `Roster` ORM model and replaced the commented-out `get_cards()` stub with a working implementation that JOINs through `RosterSlot`. A migration script at `migrations/migrate_roster_junction_table.py` reads the legacy `card_N_id` columns via raw SQL and backfills the new table. The legacy columns remain in the DB schema until an operator drops them after verifying the migration.
cal added the
ai-pr-opened
label 2026-03-04 15:33:49 +00:00
cal closed this issue 2026-03-07 03:23:42 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-database#29
No description provided.