I am working on inserting the teams into the teams table and got it to successfully populate the table with the following bash script
#! /bin/bash
if [[ $1 == "test" ]]
then
PSQL="psql --username=postgres --dbname=worldcuptest -t --no-align -c"
else
PSQL="psql --username=freecodecamp --dbname=worldcup -t --no-align -c"
fi
# Do not change code above this line. Use the PSQL variable above to query your database.
# Clear both tables and read the csv file
echo $($PSQL "TRUNCATE TABLE games, teams;")
cat games.csv | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
# Check if not on first line of csv file
if [[ $YEAR != year ]]
then
# Recieve winning and opposing team ID's
WINNER_ID = $($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
OPPONENT_ID = $($PSQL "SELECT team_id FROM teams WHERE name='$OPPONENT'")
# Add winning team to teams table if not already present, then retrieve it from the table
if [[ -z $WINNER_ID ]]
then
INSERT_WINNER = $($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
WINNER_ID = $($PSQL "SELECT team_id FROM teams WHERE name='$WINNER'")
fi
# Add opposing team to teams table if not already present, then retrieve it from the table
if [[ -z $OPPONENT_ID ]]
then
INSERT_OPPONENT = $($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")
OPPONENT_ID = $($PSQL "SELECT team_id FROM teams WHERE name='$OPPONENT'")
fi
fi
done
It fills the table with 24 teams, but I get the SUBTASKS 1.1 “before all” hook for “:1 “worldcup” database should exist” error. I switched my bash directory to the .freeCodeCamp directory to increase the mocha timer like some forum posts have said, but when I enter this command:
sed 's/20000/50000/' -i /home/codeally/project/.freeCodeCamp/package.json
It gives me the following error:
sed: can't read /home/codeally/project/.freeCodeCamp/package.json: No such file or directory
What am I doing wrong here?