strip-stats/nfldb-update_with_workaround.sh
2017-08-25 18:22:45 -05:00

26 lines
1.3 KiB
Bash

#!/bin/sh
# This is a workaround for an error that occurs when running 'nfldb-update' where some of the JSON data it
# gets from the internet contains "JAX" instead of "JAC" as the key for the Jacksonville Jaguars team
# Workaround
# Temporarily add a new team with the bad key
psql --username=nfldb nfldb --command="INSERT INTO team VALUES ('JAX', 'Jacksonville', 'Jaguars')"
# Run nfldb-update - shouldn't have the error since it finds a matching team with bad key, "JAX"
nfldb-update
# Check which tables have been populated with the bad key:
psql --username=nfldb nfldb --command="SELECT COUNT(*) FROM play WHERE pos_team = 'JAX'"
psql --username=nfldb nfldb --command="SELECT COUNT(*) FROM drive WHERE pos_team = 'JAX'"
psql --username=nfldb nfldb --command="SELECT COUNT(*) FROM game WHERE home_team = 'JAX'"
psql --username=nfldb nfldb --command="SELECT COUNT(*) FROM game WHERE away_team = 'JAX'"
psql --username=nfldb nfldb --command="SELECT COUNT(*) FROM player WHERE team = 'JAX'"
psql --username=nfldb nfldb --command="SELECT COUNT(*) FROM play_player WHERE team = 'JAX'"
# Fix all the tables where the bad key appears
psql --username=nfldb nfldb --command="UPDATE play SET pos_team = 'JAC' WHERE pos_team = 'JAX'"
# Delete the team with the bad key
psql --username=nfldb nfldb --command="DELETE FROM team WHERE team_id = 'JAX'"