another thing i noticed is the instructions say:
The tests have a 20 second limit, so try to make your script efficient. The less you have to query the database, the faster it will be. You can empty the rows in the tables of your database with TRUNCATE TABLE games, teams;
So you will need to add a truncate statement at the start of your script here.
Edit:
Okay did a little bit of testing with your script. If you erase this statement:
# Insert game data
$PSQL "INSERT INTO games (year, round, winner_id, opponent_id, winner_goals, opponent_goals)
SELECT
$year,
'$round',
(SELECT team_id FROM $TEAMS_TABLE_NAME WHERE name = '$winner'),
(SELECT team_id FROM $TEAMS_TABLE_NAME WHERE name = '$opponent'),
$winner_goals,
$opponent_goals
ON CONFLICT (year, round, winner_id, opponent_id) DO NOTHING;"
the tests run again.
So something here is not working well with the tests.
You can break up the code and run the selects separately first to get the ids then run an insert?
2nd edit:
AND, if you just erase the ON CONFLICT bit, the tests also run!!!