Commit Graph

20 Commits

Author SHA1 Message Date
Cal Corum
40c512c665 Add PostgreSQL compatibility fixes for query ordering
- Add explicit ORDER BY id to all queries for consistent results across SQLite and PostgreSQL
- PostgreSQL does not guarantee row order without ORDER BY, unlike SQLite
- Skip table creation when DATABASE_TYPE=postgresql (production tables already exist)
- Fix datetime handling in notifications (PostgreSQL native datetime vs SQLite timestamp)
- Fix grouped query count() calls that don't work in PostgreSQL
- Update .gitignore to include storage/templates/ directory

This completes the PostgreSQL migration compatibility layer while maintaining
backwards compatibility with SQLite for local development.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 10:39:14 -06:00
Cal Corum
cb89a61196 Fix PostgreSQL upsert column names and CSV null handling
- Fix upsert_many() to use column_name for EXCLUDED references
  (ForeignKeyField columns end in _id, e.g., batter -> batter_id)
- Add null checks in batting/pitching CSV output for player, team, game
  fields to prevent 'NoneType' not subscriptable errors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 17:28:40 -06:00
Cal Corum
92fc101e38 Fix PostgreSQL compatibility for GROUP BY queries and aggregations
- Fix NULL handling for FK checks in stratplays.py: use x.field_id instead
  of x.field to avoid triggering FK lookups on potentially missing rows
- Cast boolean is_start to integer for SUM() - PostgreSQL cannot sum booleans
- Add missing GROUP BY clause to Decision aggregate query
- Add Case import for boolean-to-integer casting
- Update migration script with boolean/datetime column mappings
- Exclude legacy battingstat/pitchingstat tables from migration
- Add comprehensive POSTGRES_MIGRATION_GUIDE.md documentation

Tested: /plays/batting and /plays/pitching endpoints work with group_by=player
2026-01-26 21:59:25 -06:00
Cal Corum
0cba52cea5 PostgreSQL migration: Complete code preparation phase
- Add db_helpers.py with cross-database upsert functions for SQLite/PostgreSQL
- Replace 12 on_conflict_replace() calls with PostgreSQL-compatible upserts
- Add unique indexes: StratPlay(game, play_num), Decision(game, pitcher)
- Add max_length to Team model fields (abbrev, sname, lname)
- Fix boolean comparison in teams.py (== 0/1 to == False/True)
- Create migrate_to_postgres.py with ID-preserving migration logic
- Create audit_sqlite.py for pre-migration data integrity checks
- Add PROJECT_PLAN.json for migration tracking
- Add .secrets/ to .gitignore for credentials

Audit results: 658,963 records across 29 tables, 2,390 orphaned stats (expected)

Based on Major Domo migration lessons learned (33 issues resolved there)
2026-01-25 23:05:54 -06:00
Cal Corum
1517283114 CLAUDE: Fix GROUP BY queries for PostgreSQL compatibility
- Refactor get_batting_totals() to conditionally build SELECT fields based on group_by parameter
- Refactor get_pitching_totals() with same pattern
- Ensures all non-aggregated SELECT fields are included in GROUP BY clause
- Based on successful Major Domo migration pattern
2025-11-07 10:25:00 -06:00
Cal Corum
0b8234f9d6 Add poop_max to game summary 2024-12-23 10:14:02 -06:00
Cal Corum
11568a2d2e Fix pitcher decisions across game_types 2024-04-27 08:50:33 -05:00
Cal Corum
b9e922acba Fix dupe PotG stats 2023-11-19 14:30:30 -06:00
Cal Corum
c884f45c17 Batting stats re24 sort update 2023-10-30 21:17:33 -05:00
Cal Corum
fb151f6bae Update gtype params 2023-10-29 14:11:08 -05:00
Cal Corum
eca69fe13c Bug fixes 2023-10-29 00:49:36 -05:00
Cal Corum
1a9f15b489 Clear excess logging 2023-10-27 20:05:12 -05:00
Cal Corum
58a0d10226 Added gauntlet query param 2023-10-27 12:54:27 -05:00
Cal Corum
4e54e36bc9 Added team record query & poopers 2023-10-26 00:35:40 -05:00
Cal Corum
cce9b8e1c5 HR count bug 2023-10-24 18:32:23 -05:00
Cal Corum
67555d3b55 Add gauntlet to player replacement check 2023-10-24 10:18:11 -05:00
Cal Corum
a49861bf31 Added /games/game-summary 2023-10-22 22:41:06 -05:00
Cal Corum
74a037b3fc Update /games and /plays for sheets import 2023-10-22 16:41:32 -05:00
Cal Corum
25be95090a Plays/pitching is functional 2023-10-21 23:32:05 -05:00
Cal Corum
edde7a1b82 StratPlays added 2023-10-21 19:54:31 -05:00