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)
Documentation can be found on :https://github.com/viktoriussuwandi/Periodic-Table-Database
This is the result to complete the Periodic Table Database project. Instructions for building this project can be found at https://www.freecodecamp.org/learn/relational-database/build-a-periodic-table-database-project/build-a-periodic-table-database
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.
- Rename the
weightcolumn toatomic_mass. - Rename the
melting_pointcolumn tomelting_point_celsiusand theboiling_pointcolumn toboiling_point_celsius. melting_point_celsiusandboiling_point_celsiuscolumns should not acceptnullvalues.- Add the
UNIQUEconstraint to thesymbolandnamecolumns from the elements table. symbolandnamecolumns should have theNOT NULLconstraint.- Set the
atomic_numbercolumn from thepropertiestable as aforeign keythat references the column of the same name in theelementstable. - Create a
typestable that will store the three types ofelements. typestable should have atype_idcolumn that is anintegerand theprimary key.typestable should have atypecolumn that's aVARCHARand cannot benull. It will store the different types from the type column in thepropertiestable.- Add three rows to your
typestable whose values are the three differenttypesfrom thepropertiestable. propertiestable should have atype_idforeign keycolumn that references thetype_idcolumn from thetypestable. It should be anINTwith theNOT NULLconstraint.- Each row in
propertiestable should have atype_idvalue that links to the correcttypefrom thetypestable. - Capitalize the
first letterof all thesymbolvalues in theelementstable. Be careful to only capitalize theletterand not change any others. - Remove all the
trailing zerosafter thedecimalsfrom each row of theatomic_masscolumn. You may need to adjust a data type toDECIMALfor this. The final values they should be are in theatomic_mass.txtfile. - You should add the
elementwithatomic number9 to your database. Itsnameis Fluorine,symbolis F,massis 18.998,melting pointis -220,boiling pointis -188.1, and it's anonmetal. - Add the element with
atomic number10 to your database. Itsnameis Neon,symbolis Ne,massis 20.18,melting pointis -248.6,boiling pointis -246.1, and it's anonmetal. - Create a
periodic_tablefolder in theprojectfolder and turn it into agitrepository withgit init. - Your
repositoryshould have amainbranch with all your commits. periodic_tablerepo should have at leastfive commits.- Create an
element.shfile in your repo folder for each program. script (.sh)file should have executable permissions.- If user run
./element.sh, it should output onlyPlease provide an element as an argument. and finish running. - If user run
./element.sh 1,./element.sh H, or./element.sh Hydrogen, it should output onlyThe 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. - If user run
./element.shscript withanother elementas input, it should get thesame outputbut with informationassociatedwith thegiven element. - If the argument input to
element.shscript doesn't exist as anatomic_number,symbol, ornamein the database, the only output should beI could not find that element in the database. - The message for the
first commitin the repo should beInitial commit. - The rest of the commit messages should start with
fix:,feat:,refactor:,chore:, ortest:. - Delete the
non existent element, whoseatomic_numberis 1000, from thetwo tables. propertiestable should not have atypecolumn.- Finish the project while on the
main branch. Theworking treeshould becleanand it should not have anyuncommitted changes.