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. Fill table services with initial data.
4. Primary Key and Foreign Key assignment.
5. Compact queries into salon.sql file.
6. Create shell scipt files and give executable permission to the file.
7. Copy & Run shell script salon.sh file.
Documentation can be found on : https://github.com/viktoriussuwandi/Salon-Appointment-Scheduler
This is the result to complete the Salon Appointment Scheduler project. Instructions for building this project can be found at https://www.freecodecamp.org/learn/relational-database/build-a-salon-appointment-scheduler-project/build-a-salon-appointment-scheduler
Follow the instructions and get all the user stories below to pass to finish the project. Create your database by logging in to psql with psql --username=freecodecamp --dbname=postgres
. You can query the database in your script with psql --username=freecodecamp --dbname=salon -c "SQL QUERY HERE"
, add more flags if you need to. Be sure to get creative, and have fun!
Don't forget to connect to your database to add tables after you create it 😄
Hints:
Your script needs to finish running after doing any of the tasks described below or the tests won't pass
The tests check the script output so don't use clear
or other commands which might erase it
See examples.txt
for example output of a passing script
The tests may add data to your database, feel free to delete it
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 salon > salon.sql
in a bash terminal (not the psql one). It will save the commands to rebuild your database in salon.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 < salon.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 salon.sql
file, as well as the final version of your salon.sh
file, in a public repository and submit the URL to it on freeCodeCamp.org.
- You should create a database named
salon
. - You should connect to your database, then create tables named
customers
,appointments
, andservices
. - Each table should have a
primary key
column that automatically increments. - Each
primary key
column should follow the naming convention,table_name_id
. For example, thecustomers
table should have acustomer_id
key. Note that there’s no s at the end ofcustomer
. - Your
appointments
table should have a customer_id foreign key that references thecustomer_id
column from thecustomers
table. - Your
appointments
table should have aservice_id
foreign key that references theservice_id
column from theservices
table. - Your
customers
table should have phone that is aVARCHAR
and must beunique
. - Your
customers
andservices
tables should have aname
column. - Your
appointments
table should have atime
column that is aVARCHAR
. - You should have at least three rows in your
services
table for the different services you offer, one with aservice_id
of1
. - You should create a script file named
salon.sh
in the project folder. - Your script file should have a
“shebang”
that usesbash
when the file is executed (use#! /bin/bash
). - Your script file should have executable permissions.
- You should not use the
clear
command in your script. - You should display a numbered list of the services you offer before the first prompt for input, each with the format
#) <service>
. For example,1) cut
, where1
is theservice_id
. - If you pick a service that doesn't exist, you should be shown the same list of services again.
- Your script should prompt users to enter a
service_id
,phone number
, aname
if they aren’t already acustomer
, and atime
. You should useread
to read these inputs into variables namedSERVICE_ID_SELECTED
,CUSTOMER_PHONE
,CUSTOMER_NAME
, andSERVICE_TIME
. - If a
phone number
entered doesn’texist
, you should get thecustomers name
and enter it, and thephone number
, into thecustomers
table. - You can create a row in the
appointments
table by running your script and entering1
,555-555-5555
,Fabio
,10:30
at eachrequest
for input if thatphone number
isn’t in thecustomers
table. The row should have thecustomer_id
for thatcustomer
, and theservice_id
for theservice
entered. - You can create another row in the
appointments
table by running your script and entering2
,555-555-5555
,11am
at each request forinput
if thatphone number
is already in thecustomers
table. The row should have thecustomer_id
for thatcustomer
, and theservice_id
for theservice
entered. - After an
appointment
is successfully added, you should output the messageI have put you down for a <service> at <time>, <name>
. For example, if the user choosescut
as theservice
,10:30
is entered for thetime
, and theirname
isFabio
in the database the output would beI have put you down for a cut at 10:30, Fabio
. Make sure your script finishes running after completing any of the tasks above, or else the tests won't pass.