Celestial Bodies
Celestial Bodies Database
Instructions
For this project, you need to log in to PostgreSQL with psql to create your database. Do that by entering psql --username=freecodecamp --dbname=postgres in the terminal. Make all the tests below pass to complete the project. Be sure to get creative, and have fun!
Don’t forget to connect to your database after you create it 😄
Here’s some ideas for other column and table names: description, has_life, is_spherical, age_in_millions_of_years, planet_types, galaxy_types, distance_from_earth.
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 universe > universe.sqlin a bash terminal (not the psql one). It will save the commands to rebuild your database inuniverse.sql. The file will be located where the command was entered. If it’s anything inside theprojectfolder, the file will be saved in the VM. You can rebuild the database by enteringpsql -U postgres < universe.sqlin a terminal where the.sqlfile 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
universe.sqlfile in a public repository and submit the URL to it on freeCodeCamp.org.
Complete the tasks below:
- You should create a database named
universe. - Be sure to connect to your database with
\c universe. Then, you should add tables namedgalaxy,star,planet, andmoon. - Each table should have a
primary key. - Each
primary keyshould automatically increment. - Each table should have a
namecolumn. - You should use the
INTdata type for at least two columns that are not a primary or foreign key. - You should use the
NUMERICdata type at least once. - You should use the
TEXTdata type at least once. - You should use the
BOOLEANdata type on at least two columns. - Each
starshould have aforeign keythat references one of the rows ingalaxy. - Each
planetshould have aforeign keythat references one of the rows instar. - Each
moonshould have aforeign keythat references one of the rows inplanet. - Your database should have at least five
tables. - Each table should have at least three rows.
- The
galaxyandstartables should each have at least six rows. - The
planettable should have at least 12 rows. - The
moontable should have at least 20 rows. - Each table should have at least three columns.
- The
galaxy,star,planet, andmoontables should each have at least five columns. - At least two columns per table should not accept
NULLvalues. - At least one column from each table should be required to be
UNIQUE. - All columns named name should be of type
VARCHAR. - Each
primary keycolumn should follow the naming conventiontable_name_id. For example : themoontable should have aprimary keycolumn namedmoon_id. - Each
foreign keycolumn should have the same name as thecolumnit is referencing.
Solution
the solution is in the file implementation.txt and the database dump is in the file universe.sql.