fix: refactor Roster from 26 FK columns to RosterSlot junction table (#29) #58
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#58
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database#29"
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
card_1..card_26FK columns from theRosterPeewee modelRosterSlotjunction table model with(roster, slot, card)fields and a unique index on(roster, slot)get_cards()helper onRoster— now returns cards ordered by slot via a proper JOINRosterSlotin thecreate_tablesblock for SQLite dev environmentsmigrations/migrate_roster_junction_table.pyto backfill existing data from the legacycard_N_idcolumnsFiles Changed
app/db_engine.py— model changesmigrations/migrate_roster_junction_table.py— data migration script (new)Notes
The legacy
card_1..card_26columns remain in the actual database schema (both SQLite dev and PostgreSQL prod) until the migration script is run and an operator drops them. The ORM model no longer references them, so they're silently ignored by Peewee.To migrate existing rosters run:
Test plan
RosterSlotmodel definition and unique indexrosterslotroster.get_cards()returns cards in slot orderCloses #29
AI Code Review
Files Reviewed
app/db_engine.py(modified)migrations/migrate_roster_junction_table.py(added)Findings
Correctness
Roster.get_cards()correctly joinsCard → RosterSlotvia Peewee's FK backref (RosterSlot.card = ForeignKeyField(Card, backref="roster_slots")). Generated SQL:SELECT card.* FROM card INNER JOIN rosterslot ON (rosterslot.card_id = card.id) WHERE rosterslot.roster_id = ? ORDER BY rosterslot.slot— correct and efficient.RosterSlotis defined afterRoster. The forward reference inget_cards()is safe — method bodies are evaluated lazily; by the time any request callsget_cards(), the module is fully loaded andRosterSlotis in scope. ✓card_{n}_id(Peewee appends_idto FK column names). ✓already_migratedguard is per-roster — idempotent and correct for a one-shot migration. ✓RosterSlotis inserted afterRosterin thecreate_tableslist, satisfying FK dependency ordering for fresh SQLite envs. ✓roster.card_1..card_26attributes, andget_cards()has no existing callers. Zero breaking changes. ✓Security
Style & Conventions
db_engine.py. ✓indexes = (((\"roster\", \"slot\"), True),)is correct Peewee composite unique index syntax. ✓Suggestions
migratedorskipped. Functionally correct; consider a thirdemptycounter for operational clarity if needed (not a blocker).db.create_tables()— sufficient, but ensure the script is run before the new image goes live in prod.Verdict: APPROVED
Clean design. Junction table refactor is correct, migration is idempotent, no existing callers are broken, and
get_cards()is logically sound. Ready to merge.Automated review by Claude PR Reviewer
5003b459e6to44b6222ad5TODO: Confirm migration is completed on both dev and prod prior to release.