{"id":19427870,"url":"https://github.com/gappeah/fcc-world-cup-db","last_synced_at":"2025-06-17T03:05:48.954Z","repository":{"id":255838504,"uuid":"852787450","full_name":"gappeah/fcc-world-cup-db","owner":"gappeah","description":"This project is part of the FreeCodeCamp Relational Database certification. The objective was to build a PostgreSQL database to store World Cup match results and create a set of Bash scripts to insert data into the database and retrieve meaningful information.","archived":false,"fork":false,"pushed_at":"2025-03-26T11:23:23.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T12:28:52.783Z","etag":null,"topics":["bash","bash-script","bash-scripting","database-schema","postgres","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":"SQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gappeah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-05T12:30:44.000Z","updated_at":"2025-03-26T11:23:26.000Z","dependencies_parsed_at":"2024-09-07T11:53:00.150Z","dependency_job_id":"e9fb3272-6cc7-4060-8a42-d084d7f3ab45","html_url":"https://github.com/gappeah/fcc-world-cup-db","commit_stats":null,"previous_names":["gappeah/fcc-world-cup-db"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gappeah/fcc-world-cup-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-world-cup-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-world-cup-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-world-cup-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-world-cup-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gappeah","download_url":"https://codeload.github.com/gappeah/fcc-world-cup-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-world-cup-db/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260281565,"owners_count":22985627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","bash-script","bash-scripting","database-schema","postgres","postgresql","sql"],"created_at":"2024-11-10T14:13:08.325Z","updated_at":"2025-06-17T03:05:48.934Z","avatar_url":"https://github.com/gappeah.png","language":"SQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# World Cup Database\n\nThis project is part of the FreeCodeCamp Relational Database certification. The objective was to build a PostgreSQL database to store World Cup match results and create a set of Bash scripts to insert data into the database and retrieve meaningful information.\n\n## Project Structure\n\n- **Database**: The database is managed using PostgreSQL.\n- **Scripts**: Bash scripts (`insert_data.sh` and `queries.sh`) were created to insert match data into the database and query the database for specific insights.\n\n### Files\n\n- `worldcup.sql`: Contains SQL commands to create the database, including tables for teams and games.\n- `games.csv`: A CSV file containing match data from the 2014 and 2018 World Cup tournaments.\n- `insert_data.sh`: A Bash script to insert data from `games.csv` into the database.\n- `queries.sh`: A Bash script to query the database and retrieve specific information.\n\n## Database Schema\n![diagram-export-09-09-2024-16_38_18](https://github.com/user-attachments/assets/0cf3a37c-845f-411d-820f-df21eef3e849)\n\nThe database consists of the following tables:\n\n### `teams` Table\n\n| Column Name | Data Type  | Constraints      |\n| ----------- | ---------- | ---------------- |\n| `team_id`   | SERIAL     | PRIMARY KEY      |\n| `name`      | VARCHAR(255) | UNIQUE, NOT NULL |\n\n### `games` Table\n\n| Column Name      | Data Type  | Constraints                           |\n| ---------------- | ---------- | ------------------------------------- |\n| `game_id`        | SERIAL     | PRIMARY KEY                           |\n| `year`           | INTEGER    | NOT NULL                              |\n| `round`          | VARCHAR(255) | NOT NULL                              |\n| `winner_goals`   | INTEGER    | NOT NULL                              |\n| `opponent_goals` | INTEGER    | NOT NULL                              |\n| `winner_id`      | INTEGER    | REFERENCES `teams(team_id)`            |\n| `opponent_id`    | INTEGER    | REFERENCES `teams(team_id)`            |\n\n## Usage\n\n### Prerequisites\n\n- **PostgreSQL**: Ensure PostgreSQL is installed and running on your machine. Connect to the database using:\n\n  ```bash\n  psql --username=freecodecamp --dbname=worldcup\n  ```\n\n- **Database Setup**: The database should be created and populated using the provided `worldcup.sql` and `games.csv` files.\n\n### Running the Script\n\n#### Insert Data into the Database\n\nTo insert data from the `games.csv` file into the database, run the `insert_data.sh` script:\n\n```bash\n./insert_data.sh\n```\n\nThis script will read the match data from `games.csv` and insert it into the `teams` and `games` tables. It will also ensure that teams are added only once.\n\n#### Query the Database\n\nTo query the database and retrieve various statistics about the World Cup matches, run the `queries.sh` script:\n\n```bash\n./queries.sh\n```\n\nThis script retrieves the following data:\n\n- Total number of goals scored by winning teams.\n- Total number of goals scored in all games by both teams.\n- Average number of goals by winning teams.\n- Average number of goals by both teams.\n- Most goals scored in a single game by one team.\n- Number of games where the winning team scored more than two goals.\n- The winner of the 2018 World Cup.\n- Teams that played in the 2014 'Eighth-Final' round.\n- Unique winning team names in the dataset.\n- Year and team name of all the champions.\n- Teams that start with 'Co'.\n\n### Example Output\n\n```bash\nTotal number of goals in all games from winning teams:\n68\n\nTotal number of goals in all games from both teams combined:\n90\n\nAverage number of goals in all games from the winning teams:\n2.1250000000000000\n\nAverage number of goals in all games from the winning teams rounded to two decimal places:\n2.13\n\nAverage number of goals in all games from both teams:\n2.8125000000000000\n\nMost goals scored in a single game by one team:\n7\n\nNumber of games where the winning team scored more than two goals:\n6\n\nWinner of the 2018 tournament team name:\nFrance\n\nList of teams who played in the 2014 'Eighth-Final' round:\nAlgeria\nArgentina\nBelgium\nBrazil\nChile\nColombia\nCosta Rica\nFrance\nGermany\nGreece\nMexico\nNetherlands\nNigeria\nSwitzerland\nUnited States\nUruguay\n\nList of unique winning team names in the whole data set:\nArgentina\nBelgium\nBrazil\nColombia\nCosta Rica\nCroatia\nEngland\nFrance\nGermany\nNetherlands\nRussia\nSweden\nUruguay\n\nYear and team name of all the champions:\n2014|Germany\n2018|France\n\nList of teams that start with 'Co':\nColombia\nCosta Rica\n```\n\n### Error Handling\n\n- If a team does not exist in the database, it will be inserted during the data insertion process.\n- The scripts ensure that no duplicate team entries are made in the `teams` table.\n\n## Project Completion\n\n### Database Fixes\n\nThe database was refined to meet the project requirements:\n\n1. The `teams` table stores unique team names.\n2. The `games` table links teams with their match outcomes, ensuring referential integrity between teams and games.\n\n### Git Repository\n\nThe project folder was initialized as a Git repository:\n\n```bash\ngit init\n```\n\nThe repository was ensured to have a `main` branch with at least five commits, using conventional prefixes like `fix:`, `feat:`, `refactor:`, etc.\n\n## Installation\n\n1. Clone this repository.\n2. Set up the database:\n   - Log in to PostgreSQL:\n     ```bash\n     psql --username=freecodecamp --dbname=postgres\n     ```\n   - Run the SQL commands in `worldcup.sql` to create and populate the database:\n     ```sql\n     \\i worldcup.sql\n     ```\n3. Make sure the `insert_data.sh` and `queries.sh` scripts have execution permissions:\n   ```bash\n   chmod +x insert_data.sh queries.sh\n   ```\n\n4. Run the scripts as described above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgappeah%2Ffcc-world-cup-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgappeah%2Ffcc-world-cup-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgappeah%2Ffcc-world-cup-db/lists"}