allow user to add new routines

This commit is contained in:
ida schmidt 2024-11-17 22:14:13 +00:00
parent 3aa6904ef0
commit 1641bda528
2 changed files with 47 additions and 47 deletions

View file

@ -23,6 +23,8 @@ repsprompt="Enter the number of repititions: "
newmachineprompt="Enter name of new machine: "
newroutineprompt="Enter name of new routine: "
# menus
routinemenu="To begin, you must select your routine
"
@ -84,8 +86,8 @@ query() {
";;
routines)
psql -tAd ${dbname} <<<"
SELECT DISTINCT routine
FROM machine;
SELECT name
FROM routine;
";;
sets)
# -tA is omitted as we're borrowing the
@ -135,6 +137,24 @@ insert() {
('${newmachine}',
'${routine[${workingroutine}]}');
";;
newroutine)
psql -qd ${dbname} <<<"
BEGIN;
INSERT INTO routine
(name)
VALUES
('${newroutine}');
CREATE TABLE IF NOT EXISTS ${newroutine} (
date date NOT NULL,
machine text NOT NULL REFERENCES machine(name),
weight real NOT NULL,
setno smallint NOT NULL,
reps smallint NOT NULL
);
COMMIT;
"
echo $?
;;
esac
}
@ -301,7 +321,15 @@ newmachine?(){
insert newmachine
fi
fi
}
newroutine?(){
if [ "${workingroutine}" = '0' ]; then
read -p "${newroutineprompt}" newroutine
if [ "${newroutine}" ]; then
insert newroutine
fi
fi
}
routines?() {
@ -309,15 +337,21 @@ routines?() {
get routines
echo "${routinemenu}"
numerate routines
echo "(0) New routine"
read -p "${selectprompt}" workingroutine
if [ -z "${workingroutine}" ]; then
newroutine?
if [ "${workingroutine}" ] &&
[ "${workingroutine}" != 0 ]; then
machine?
fi
if [ -z "${workingroutine}" ] ||
[ "${newroutine}" ]; then
routines?
fi
}
main() {
routines?
machine?
}
### function calls

View file

@ -8,49 +8,18 @@
--
-- Tables
--
-- currently there is a table for each day
-- in the routine, and a table to catalog
-- which machine belongs to which routine
-- The script will add tables for each routine with
-- a foreign key reference to machine(name)
--
CREATE TABLE public.arms (
date date NOT NULL,
machine text NOT NULL,
weight real NOT NULL,
setno smallint NOT NULL,
reps smallint NOT NULL
);
CREATE TABLE public.core (
date date NOT NULL,
machine text NOT NULL,
weight real NOT NULL,
setno smallint NOT NULL,
reps smallint NOT NULL
);
CREATE TABLE public.legs (
date date NOT NULL,
machine text NOT NULL,
weight real NOT NULL,
setno smallint NOT NULL,
reps smallint NOT NULL
);
CREATE TABLE public.machine (
name text NOT NULL,
routine text NOT NULL
);
--
-- Sample data (routine listing requires a machine this table) (bad design)
--
COPY public.machine (name, routine) FROM stdin;
leg press legs
bench press arms
sit ups core
\.
CREATE TABLE public.routine (
name text NOT NULL
);
--
-- Constraints
@ -59,11 +28,8 @@ sit ups core
ALTER TABLE ONLY public.machine
ADD CONSTRAINT machine_pkey PRIMARY KEY (name);
ALTER TABLE ONLY public.arms
ADD CONSTRAINT arms_machine_fkey FOREIGN KEY (machine) REFERENCES public.machine(name);
ALTER TABLE ONLY public.routine
ADD CONSTRAINT routine_pkey PRIMARY KEY (name);
ALTER TABLE ONLY public.core
ADD CONSTRAINT core_machine_fkey FOREIGN KEY (machine) REFERENCES public.machine(name);
ALTER TABLE ONLY public.legs
ADD CONSTRAINT legs_machine_fkey FOREIGN KEY (machine) REFERENCES public.machine(name);
ALTER TABLE ONLY public.machine
ADD CONSTRAINT machine_routine_fkey FOREIGN KEY (routine) REFERENCES public.routine(name);