History data
Use this page to import historical football data from Football-Data into the database and to rebuild derived statistics tables. Each section is independent — run them in any order as needed.
Section 1: Download match data by competition (history)
Fetches finished matches from Football-Data for the selected competitions and date range. READS/CREATES: sport_events. WRITES: match_events, match_metadata, match_summaries, match_lineups. CLEARS (full refresh only): match_events, match_metadata, match_summaries, match_lineups (keeps sport_events). The date range is split into 10-day windows automatically to stay within API rate limits.
Section 2: Download specific matches by ID (history-for-matches)
Fetches and imports one or more specific matches by their Football-Data numeric IDs. READS/CREATES: sport_events. DELETES + REINSERTS (per match): match_events, match_lineups. UPSERTS: match_metadata, match_summaries. Use this to fill in individual missing matches without re-running a full date-range download.
Section 3: Download match statistics (home/away) (history-statistics)
Fetches detailed team-level match statistics from Football-Data and stores home/away records in the database. READS/CREATES: sport_events. WRITES/UPSERTS: match_statistics. CLEARS (full refresh only): match_statistics. Select competitions and date range; the range is split into 10-day windows to respect API limits.
Section 4: Rebuild market variables (update-market-vars)
Calculates and stores market variables for each match based on database events. READS: match_metadata, match_events. WRITES: market_vars_1x2, market_vars_1x2_btts, market_vars_1x2_over_under, market_vars_btts, market_vars_btts_over_under, market_vars_correct_score, market_vars_double_chance, market_vars_double_chance_btts, market_vars_draw_no_bet, market_vars_ht_ft, market_vars_over_under, market_vars_total_goals_home_away. CLEARS (All matches mode): all listed market_vars_* tables first.
Section 5: Rebuild player match statistics (update-player-match-stats)
Aggregates per-player statistics for every match in the database. READS: match_events. CLEARS: player_match_stats. WRITES/UPSERTS: player_match_stats.
Section 6: Rebuild red card statistics (update-red-card-stats)
Reads booking events from the database, filters red-card events, and rebuilds red-card statistics. READS: match_events. CLEARS: red_cards_stats. WRITES/UPSERTS: red_cards_stats.
Section 7: Rebuild team statistics (update-stats)
Recalculates team-level statistics using SQL queries loaded from Google Sheets. WRITES/UPSERTS: stats. READS: match_metadata (to build team-competition pairs) plus any additional tables referenced by the Google Sheets SQL queries.