0% found this document useful (0 votes)
350 views5 pages

Salon Database

- The document provides instructions for completing a project that involves creating a database and tables to manage a salon's customers, services, and appointments. - It outlines tasks like creating tables for customers, services, and appointments with the appropriate columns and primary/foreign keys. - It also describes populating the tables with sample data and creating a shell script to interact with the database by allowing users to book appointments.

Uploaded by

Divya Sriju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
350 views5 pages

Salon Database

- The document provides instructions for completing a project that involves creating a database and tables to manage a salon's customers, services, and appointments. - It outlines tasks like creating tables for customers, services, and appointments with the appropriate columns and primary/foreign keys. - It also describes populating the tables with sample data and creating a shell script to interact with the database by allowing users to book appointments.

Uploaded by

Divya Sriju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

https://drive.google.

com/drive/folders/1GdxHMmhhNtE1uywGX_IqEgjBPNj6SC_L

Instructions
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.

Complete the tasks below

You should create a database named salon

You should connect to your database, then create tables named customers,
appointments, and services

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, the customers table should have a customer_id key. Note that there’s no s
at the end of customer

Your appointments table should have a customer_id foreign key that references the
customer_id column from the customers table

Your appointments table should have a service_id foreign key that references the
service_id column from the services table

Your customers table should have phone that is a VARCHAR and must be unique

Your customers and services tables should have a name column

Your appointments table should have a time column that is a VARCHAR


You should have at least three rows in your services table for the different
services you offer, one with a service_id of 1

You should create a script file named salon.sh in the project folder

Your script file should have a “shebang” that uses bash 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, where 1
is the service_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, a name if they
aren’t already a customer, and a time. You should use read to read these inputs
into variables named SERVICE_ID_SELECTED, CUSTOMER_PHONE, CUSTOMER_NAME, and
SERVICE_TIME

If a phone number entered doesn’t exist, you should get the customers name and
enter it, and the phone number, into the customers table

You can create a row in the appointments table by running your script and entering
1, 555-555-5555, Fabio, 10:30 at each request for input if that phone number isn’t
in the customers table. The row should have the customer_id for that customer, and
the service_id for the service entered

You can create another row in the appointments table by running your script and
entering 2, 555-555-5555, 11am at each request for input if that phone number is
already in the customers table. The row should have the customer_id for that
customer, and the service_id for the service entered

After an appointment is successfully added, you should output the message I have
put you down for a <service> at <time>, <name>. For example, if the user chooses
cut as the service, 10:30 is entered for the time, and their name is Fabio in the
database the output would be I 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

--

CREATE DATABASE salon

CREATE TABLE public.appointments (


appointment_id integer NOT NULL,
customer_id integer NOT NULL,
service_id integer NOT NULL,
"time" character varying(10)
);
CREATE TABLE public.customers (
customer_id integer NOT NULL,
name character varying(20) NOT NULL,
phone character varying(15) NOT NULL
);

CREATE TABLE public.services (


service_id integer NOT NULL,
name character varying(20)
);

--

INSERT INTO public.appointments VALUES (41, 36, 1, '10:30');


INSERT INTO public.appointments VALUES (42, 36, 2, '11am');

--

INSERT INTO public.customers VALUES (36, 'Fabio', '555-555-5555');

INSERT INTO public.services VALUES (1, 'Haircut');


INSERT INTO public.services VALUES (2, 'Nails');
INSERT INTO public.services VALUES (3, 'Hair Coloring');
INSERT INTO public.services VALUES (4, 'Beard Grooving');
INSERT INTO public.services VALUES (5, 'Shaving');

e: CONSTRAINT; Schema: public; Owner: freecodecamp


--

ALTER TABLE ONLY public.appointments


ADD CONSTRAINT appointments_pkey PRIMARY KEY (appointment_id);

--
-- Name: customers customers_phone_key; Type: CONSTRAINT; Schema: public; Owner:
freecodecamp
--

ALTER TABLE ONLY public.customers


ADD CONSTRAINT customers_phone_key UNIQUE (phone);

--
-- Name: customers customers_pkey; Type: CONSTRAINT; Schema: public; Owner:
freecodecamp
--
ALTER TABLE ONLY public.customers
ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);

--
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner:
freecodecamp
--

ALTER TABLE ONLY public.services


ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);

--
-- Name: appointments appointments_customer_id_fkey; Type: FK CONSTRAINT; Schema:
public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments


ADD CONSTRAINT appointments_customer_id_fkey FOREIGN KEY (customer_id)
REFERENCES public.customers(customer_id);

--
-- Name: appointments appointments_service_id_fkey; Type: FK CONSTRAINT; Schema:
public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments


ADD CONSTRAINT appointments_service_id_fkey FOREIGN KEY (service_id) REFERENCES
public.services(service_id);

--##########################

#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n*** Artyom's Salon ***\n"
echo -e "Welcome to Artyom's Salon, how may I help you?\n"
MAIN_MENU(){
if [[ $1 ]]
then
echo -e "\n$1\n"
fi

SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")


echo "$SERVICES" | sed 's/|/ /g' | while read SERV_ID SERV_N
do
echo "$SERV_ID) $SERV_N"
done
echo "0 for Exit"
read SERVICE_ID_SELECTED
SERV_EXIST=$($PSQL "SELECT name FROM services WHERE
service_id=$SERVICE_ID_SELECTED")

if [[ $SERVICE_ID_SELECTED == 0 ]]
then
exit
else
if [[ -z $SERV_EXIST ]]
then
MAIN_MENU "The selected service does not exist, select again:"
else
echo "What's your phone number?"
ENTER_PHONE(){
read CUSTOMER_PHONE
if [[ -z $CUSTOMER_PHONE ]]
then
echo "You didn't enter a phone number, try again:"
ENTER_PHONE
else
PHONE_EXIST=$($PSQL "SELECT name FROM customers WHERE phone='$PHONE'")
if [[ -z $PHONE_EXIST ]]
then
echo "I don't have a record for that phone number, what's your name?"
ENTER_NAME(){
read CUSTOMER_NAME
if [[ -z $CUSTOMER_NAME ]]
then
echo "You didn't enter your name, try again:"
ENTER_NAME
else
CLIENT_REG=$($PSQL "INSERT INTO customers(phone, name)
VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
}
ENTER_NAME
else
CUSTOMER_NAME=$PHONE_EXIST
fi
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE
service_id=$SERVICE_ID_SELECTED" | sed 's/^ *//g')
echo -e "What time would you like your $SERVICE_NAME, $CLIENT_N?"
ENTER_TIME(){
read SERVICE_TIME
if [[ -z $SERVICE_TIME ]]
then
echo "You didn't enter an appointment time, try again:"
ENTER_TIME
else
CLIENT_ID=$($PSQL "SELECT customer_id FROM customers WHERE
phone='$CUSTOMER_PHONE'")
APP_REG=$($PSQL "INSERT INTO appointments(customer_id, service_id,
time) VALUES($CLIENT_ID, $SELECTED, '$SERVICE_TIME')")

echo -e "I have put you down for a $SERVICE_NAME at $SERVICE_TIME,


$CLIENT_N."
fi
}
ENTER_TIME
fi
}
ENTER_PHONE
fi
fi
}
MAIN_MENU

You might also like