Skip to content

A Bash script for querying a periodic table database to retrieve information about chemical elements. The project includes a database dump (periodic_table.sql) and a script file (element.sh) to interact with the data.

Notifications You must be signed in to change notification settings

davidecarluccio/periodic-table-database

 
 

Repository files navigation

Build a Periodic Table Database

This is one of the required projects to earn your certification. For this project, you will create a Bash script to get information about chemical elements from a periodic table database.

This course runs in a virtual Linux machine using Gitpod. Follow these instructions to start the course:

  1. Create a GitHub account if you don't have one
  2. Click the start button below
  3. Login to Gitpod with your GitHub account if you aren't already
  4. 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
  5. Follow the instructions in CodeRoad to complete the course

Complete both steps below to finish the challenge.


Step 1: Complete the project

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 periodic_table.sql file, as well as your element.sh file, so you can complete step 2. There will be instructions on 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 Periodic Table 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 Periodic Table 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. Compact sql db schema into periodic_table.sql.
2. Prepare git directory.
3. Prepare shell scipt files.
4. Copy scipts and run the scripts (fix db first)

Instructions

You are started with a periodic_table database that has information about some chemical elements. You can connect to it by entering psql --username=freecodecamp --dbname=periodic_table in the terminal. You may want to get a little familiar with the existing tables, columns, and rows. Read the instructions below and complete user stories to finish the project. Certain tests may not pass until other user stories are complete. Good luck!

Part 1: Fix the database

There are some mistakes in the database that need to be fixed or changed. See the user stories below for what to change.

Part 2: Create your git repository

You need to make a small bash program. The code needs to be version controlled with git, so you will need to turn the suggested folder into a git repository.

Part 3: Create the script

Lastly, you need to make a script that accepts an argument in the form of an atomic number, symbol, or name of an element and outputs some information about the given element. In your script, you can create a PSQL variable for querying the database like this: PSQL="psql --username=freecodecamp --dbname=<database_name> -t --no-align -c", add more flags if you need to.

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 periodic_table > periodic_table.sql in a bash terminal (not the psql one). It will save the commands to rebuild your database in periodic_table.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 < periodic_table.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 periodic_table.sql file, as well as the final version of your element.sh file, in a public repository and submit the URL to it on freeCodeCamp.org.

CodeRoad

  1. Rename the weight column to atomic_mass.
  2. Rename the melting_point column to melting_point_celsius and the boiling_point column to boiling_point_celsius.
  3. melting_point_celsius and boiling_point_celsius columns should not accept null values.
  4. Add the UNIQUE constraint to the symbol and name columns from the elements table.
  5. symbol and name columns should have the NOT NULL constraint.
  6. Set the atomic_number column from the properties table as a foreign key that references the column of the same name in the elements table.
  7. Create a types table that will store the three types of elements.
  8. types table should have a type_id column that is an integer and the primary key.
  9. types table should have a type column that's a VARCHAR and cannot be null. It will store the different types from the type column in the properties table.
  10. Add three rows to your types table whose values are the three different types from the properties table.
  11. properties table should have a type_id foreign key column that references the type_id column from the types table. It should be an INT with the NOT NULL constraint.
  12. Each row in properties table should have a type_id value that links to the correct type from the types table.
  13. Capitalize the first letter of all the symbol values in the elements table. Be careful to only capitalize the letter and not change any others.
  14. Remove all the trailing zeros after the decimals from each row of the atomic_mass column. You may need to adjust a data type to DECIMAL for this. The final values they should be are in the atomic_mass.txt file.
  15. You should add the element with atomic number 9 to your database. Its name is Fluorine, symbol is F, mass is 18.998, melting point is -220, boiling point is -188.1, and it's a nonmetal.
  16. Add the element with atomic number 10 to your database. Its name is Neon, symbol is Ne, mass is 20.18, melting point is -248.6, boiling point is -246.1, and it's a nonmetal.
  17. Create a periodic_table folder in the project folder and turn it into a git repository with git init.
  18. Your repository should have a main branch with all your commits.
  19. periodic_table repo should have at least five commits.
  20. Create an element.sh file in your repo folder for each program.
  21. script (.sh) file should have executable permissions.
  22. If user run ./element.sh, it should output only Please provide an element as an argument. and finish running.
  23. If user run ./element.sh 1, ./element.sh H, or ./element.sh Hydrogen, it should output only The element with atomic number 1 is Hydrogen (H). It's a nonmetal, with a mass of 1.008 amu. Hydrogen has a melting point of -259.1 celsius and a boiling point of -252.9 celsius.
  24. If user run ./element.sh script with another element as input, it should get the same output but with information associated with the given element.
  25. If the argument input to element.sh script doesn't exist as an atomic_number, symbol, or name in the database, the only output should be I could not find that element in the database.
  26. The message for the first commit in the repo should be Initial commit.
  27. The rest of the commit messages should start with fix:, feat:, refactor:, chore:, or test:.
  28. Delete the non existent element, whose atomic_number is 1000, from the two tables.
  29. properties table should not have a type column.
  30. Finish the project while on the main branch. The working tree should be clean and it should not have any uncommitted changes.

Step 2: Submit your code

When you have completed the project, save all the required files into a public repository and submit the URL to it below.

Required files: periodic_table.sql, element.sh

About

A Bash script for querying a periodic table database to retrieve information about chemical elements. The project includes a database dump (periodic_table.sql) and a script file (element.sh) to interact with the data.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%