This is one of the required projects to earn your certification. For this project, you will create a Bash script that enters information from World Cup games into PostgreSQL, then query the database for useful statistics.
This course runs in a virtual Linux machine using Gitpod. Follow these instructions to start the course:
- Create a GitHub account if you don't have one
- Click the start button below
- Login to Gitpod with your GitHub account if you aren't already
- Once the virtual Linux machine is finished loading, start the CodeRoad extension by:
- Clicking the "hamburger" menu near the top left of the VSCode window,
- Going to the "View" menu,
- Clicking on the "Command Palette" option,
- and running the "CodeRoad: Start" command
- Follow the instructions in CodeRoad to complete the course
Complete both steps below to finish the challenge.
The project runs in a virtual machine, complete the user stories described in there and get all the tests to pass to finish step 1.
Important: After you pass all the project tests, save a dump of your database into a worldcup.sql file, as well as your insert_data.sh and queries.sh files, so you can complete step 2. There will be instructions how to do that within the virtual machine.
Clicking the button below will start a new project. If you have previously started the Build a World Cup Database course, go to your Gitpod dashboard to continue.
Learn more about Gitpod workspaces.
If you log out of freeCodeCamp before you complete the entire Build a World Cup Database course, your progress will not be saved to your freeCodeCamp account.
Open file solution.txt To follow my terminal command. Solutions divided into several steps :
1. Create Database and connect to it.
2. Create tables as required conditions.
3. Primary Key and Foreign Key assignment.
4. Give executable permission to shell scipt files.
5. Copy & Run shell script files (NOTE : insert data first).
6. Compact queries into worldcup.sql file.
Follow the instructions and get all the user stories below to pass to finish the project.
You start with several files, one of them is games.csv. It contains a comma-separated list of all games of the final three rounds of the World Cup tournament since 2014; the titles are at the top. It includes the year of each game, the round of the game, the winner, their opponent, and the number of goals each team scored. You need to do three things for this project:
Log into the psql interactive terminal with psql --username=freecodecamp --dbname=postgres and create your database structure according to the user stories below.
Don't forget to connect to the database after you create it.
Complete the insert_data.sh script to correctly insert all the data from games.csv into the database. The file is started for you. Do not modify any of the code you start with. Using the PSQL variable defined, you can make database queries like this: $($PSQL "<query_here>"). 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;
Complete the empty echo commands in the queries.sh file to produce output that matches the expected_output.txt file. The file has some starter code, and the first query is completed for you. Use the PSQL variable defined to complete rest of the queries. Note that you need to have your database filled with the correct data from the script to get the correct results from your queries. Hint: Test your queries in the psql prompt first and then add them to the script file.
Notes:
If you leave your virtual machine, your database may not be saved. You can make a dump of it by entering pg_dump -cC --inserts -U freecodecamp worldcup > worldcup.sql in a bash terminal (not the psql one). It will save the commands to rebuild your database in worldcup.sql. The file will be located where the command was entered. If it's anything inside the project folder, the file will be saved in the VM. You can rebuild the database by entering psql -U postgres < worldcup.sql in a terminal where the .sql file is.
If you are saving your progress on freeCodeCamp.org, after getting all the tests to pass, follow the instructions above to save a dump of your database. Save the worldcup.sql file, as well as the final version of your insert_data.sh and queries.sh files, in a public repository and submit the URL to it on freeCodeCamp.org.
- You should create a database named
worldcup. - You should connect to your worldcup database and then create
teamsandgamestables. - Your
teamstable should have ateam_idcolumn that is a type ofSERIALand is the primary key, and anamecolumn that has to beUNIQUE. - Your
gamestable should have agame_idcolumn that is a type ofSERIALand is the primary key, ayearcolumn of typeINT, and aroundcolumn of typeVARCHAR. - Your
gamestable should havewinner_idandopponent_idforeign key columns that each referenceteam_idfrom theteamstable. - Your
gamestable should havewinner_goalsandopponent_goalscolumns that are typeINT. - All of your columns should have the
NOT NULLconstraint. - Your two script (
.sh) files should haveexecutable permissions. Othertestsinvolving these two files will fail until permissions are correct. When thesepermissionsare enabled, the tests will take significantly longer to run. - When you run your
insert_data.shscript, it should add eachunique teamto theteamstable. There should be24rows. - When you run your
insert_data.shscript, it should insert arowfor each line in thegames.csvfile (other than the top line of the file). There should be32rows. Each row should have every column filled in with the appropriate info. Make sure to add the correct ID's from theteamstable (you cannot hard-code the values). - You should correctly complete the queries in the
queries.shfile. Fill in each empty echo command to get the output of what is suggested with the command above it. Only use a single line like the first query. The output should match what is in theexpected_output.txtfile exactly, take note of the number of decimal places in some of the query results.
When you have completed the project, save all the required files into a public repository and submit the URL to it below.
Required files: worldcup.sql, insert_data.sh, queries.sh