Skill 02 / 03
SQL & PostgreSQL
Two database schemas drawn from their SQL files, and the queries of a Bash script.
- SQL, PostgreSQL and Bash(verified)
Overview
Two freeCodeCamp database projects, from my public repositories: a PostgreSQL schema of galaxies, stars, planets and moons, and a salon appointment scheduler written in Bash on top of psql. The diagrams are drawn from the SQL files themselves.
On this page
SQL, PostgreSQL and Bash (verified)
See proof
Claim
SQL, PostgreSQL and Bash
✓ Verified
Evidence
- freeCodeCamp: Relational Database · freecodecamp · checked 29 September 2026Issued 27 Sep 2026. Checked on the public freeCodeCamp API.
- freeCodeCamp: Relational Database V8 · freecodecamp · checked 29 September 2026Issued 26 Sep 2026. Checked on the public freeCodeCamp API.
- celestial-bodies-database · github · checked 28 September 2026PostgreSQL database project (freeCodeCamp).
- salon-appointment-scheduler · github · checked 28 September 2026Bash + SQL appointment scheduler (freeCodeCamp).
- Celestial bodies database: the whole SQL file (universe.sql, lines 1–464) · manual · checked 2 October 2026From commit c2b1392 (18 Sep 2026) by zurukzuruk1 in the celestial-bodies-database repository. Copied whole on 02/10/2026 (line endings normalised).
- Salon appointment scheduler: the whole SQL file (salon.sql, lines 1–267) · manual · checked 2 October 2026From commit 5c04648 (25 Sep 2026) by zurukzuruk1 in the salon-appointment-scheduler repository. Copied whole on 02/10/2026 (line endings normalised).
- Salon appointment scheduler: the query lines of the script (salon.sh, lines 14–57) · manual · checked 2 October 2026From commit 5c04648 (25 Sep 2026) by zurukzuruk1 in the salon-appointment-scheduler repository. Copied verbatim on 02/10/2026 (line endings normalised).
Result
Two freeCodeCamp Relational Database certifications (one with 5 projects) and two public database projects on GitHub.
Who wrote this code
“I wrote the freeCodeCamp exercise code shown on the Skills pages.”
See proof
Claim
I wrote the freeCodeCamp exercise code shown on the Skills pages.
Stated by Danilo
Evidence
- Case converter source: the four case functions (build-a-case-converter/case_converter/index.js, lines 1–20) · manual · checked 2 October 2026From commit a3d68af (26 Sep 2026) by zurukzuruk1 in the back-end-development-and-apis repository. Copied verbatim on 02/10/2026 (line endings normalised).
- Case converter test: four assert.strictEqual checks (build-a-case-converter/case_converter/index.test.js, lines 1–18) · manual · checked 2 October 2026From commit a3d68af (26 Sep 2026) by zurukzuruk1 in the back-end-development-and-apis repository. Copied verbatim on 02/10/2026 (line endings normalised).
- Prime number checker source: isPrime (build-a-prime-number-checker-module/index.js, lines 1–11) · manual · checked 2 October 2026From commit a3d68af (26 Sep 2026) by zurukzuruk1 in the back-end-development-and-apis repository. Copied verbatim on 02/10/2026 (line endings normalised).
- JWT-protected routes source: register and login with bcrypt and JWT (build-jwt-protected-routes/routes/auth.js, lines 11–52) · manual · checked 2 October 2026From commit a3d68af (26 Sep 2026) by zurukzuruk1 in the back-end-development-and-apis repository. Copied verbatim on 02/10/2026 (line endings normalised).
- Bank API source: the transfer route and its checks (build-a-bank-api/server.js, lines 30–71) · manual · checked 2 October 2026From commit a3d68af (26 Sep 2026) by zurukzuruk1 in the back-end-development-and-apis repository. Copied verbatim on 02/10/2026 (line endings normalised).
- Celestial bodies database: the whole SQL file (universe.sql, lines 1–464) · manual · checked 2 October 2026From commit c2b1392 (18 Sep 2026) by zurukzuruk1 in the celestial-bodies-database repository. Copied whole on 02/10/2026 (line endings normalised).
- Salon appointment scheduler: the whole SQL file (salon.sql, lines 1–267) · manual · checked 2 October 2026From commit 5c04648 (25 Sep 2026) by zurukzuruk1 in the salon-appointment-scheduler repository. Copied whole on 02/10/2026 (line endings normalised).
- Salon appointment scheduler: the query lines of the script (salon.sh, lines 14–57) · manual · checked 2 October 2026From commit 5c04648 (25 Sep 2026) by zurukzuruk1 in the salon-appointment-scheduler repository. Copied verbatim on 02/10/2026 (line endings normalised).
Result
The code is copied verbatim from public repositories, where it was committed by Danilo's GitHub account (zurukzuruk1). That he wrote it himself is his statement of 2 Oct 2026.
Schema
Both diagrams are generated when the site is built, by reading the CREATE TABLE statements and the key constraints of the verbatim SQL files: columns and types, primary keys, unique columns and foreign keys. Nothing is drawn by hand.
Celestial bodies database: universe.sql
Evidence tier: Existing evidence · drawn from the file
5 tables · 4 foreign keys · 27 columns
universe.sql: 5 tables and 4 foreign keys, read from the file when this site was built. Each line joins a foreign-key column (○) to the column it references (●). PK primary key, FK foreign key, UQ unique.Tables, columns and keys as text
galaxy
| Column | Type | Not null | Keys |
|---|---|---|---|
galaxy_id | integer | yes | primary key |
name | character varying(255) | yes | unique |
galaxy_type_id | integer | no | foreign key |
distance_from_earth | numeric | yes | – |
has_dark_matter | boolean | no | – |
diameter_light_years | integer | no | – |
galaxy_type
| Column | Type | Not null | Keys |
|---|---|---|---|
galaxy_type_id | integer | yes | primary key |
name | character varying(255) | yes | unique |
description | text | yes | – |
moon
| Column | Type | Not null | Keys |
|---|---|---|---|
moon_id | integer | yes | primary key |
name | character varying(255) | yes | unique |
planet_id | integer | yes | foreign key |
has_atmosphere | boolean | no | – |
diameter_km | numeric | no | – |
discovery_year | integer | no | – |
planet
| Column | Type | Not null | Keys |
|---|---|---|---|
planet_id | integer | yes | primary key |
name | character varying(255) | yes | unique |
star_id | integer | yes | foreign key |
has_rings | boolean | no | – |
orbital_period_days | numeric | no | – |
moons_count | integer | no | – |
star
| Column | Type | Not null | Keys |
|---|---|---|---|
star_id | integer | yes | primary key |
name | character varying(255) | yes | unique |
galaxy_id | integer | yes | foreign key |
mass_solar_masses | numeric | no | – |
is_variable | boolean | no | – |
age_million_years | integer | no | – |
Foreign keys
| Column | References |
|---|---|
galaxy.galaxy_type_id | galaxy_type.galaxy_type_id |
moon.planet_id | planet.planet_id |
planet.star_id | star.star_id |
star.galaxy_id | galaxy.galaxy_id |
Show the whole file (464 lines)
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.22 (Ubuntu 12.22-0ubuntu0.20.04.4)
-- Dumped by pg_dump version 12.22 (Ubuntu 12.22-0ubuntu0.20.04.4)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: galaxy; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.galaxy (
galaxy_id integer NOT NULL,
name character varying(255) NOT NULL,
galaxy_type_id integer,
distance_from_earth numeric NOT NULL,
has_dark_matter boolean,
diameter_light_years integer
);
--
-- Name: galaxy_galaxy_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.galaxy_galaxy_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: galaxy_galaxy_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.galaxy_galaxy_id_seq OWNED BY public.galaxy.galaxy_id;
--
-- Name: galaxy_type; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.galaxy_type (
galaxy_type_id integer NOT NULL,
name character varying(255) NOT NULL,
description text NOT NULL
);
--
-- Name: galaxy_type_galaxy_type_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.galaxy_type_galaxy_type_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: galaxy_type_galaxy_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.galaxy_type_galaxy_type_id_seq OWNED BY public.galaxy_type.galaxy_type_id;
--
-- Name: moon; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.moon (
moon_id integer NOT NULL,
name character varying(255) NOT NULL,
planet_id integer NOT NULL,
has_atmosphere boolean,
diameter_km numeric,
discovery_year integer
);
--
-- Name: moon_moon_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.moon_moon_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: moon_moon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.moon_moon_id_seq OWNED BY public.moon.moon_id;
--
-- Name: planet; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.planet (
planet_id integer NOT NULL,
name character varying(255) NOT NULL,
star_id integer NOT NULL,
has_rings boolean,
orbital_period_days numeric,
moons_count integer
);
--
-- Name: planet_planet_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.planet_planet_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: planet_planet_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.planet_planet_id_seq OWNED BY public.planet.planet_id;
--
-- Name: star; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.star (
star_id integer NOT NULL,
name character varying(255) NOT NULL,
galaxy_id integer NOT NULL,
mass_solar_masses numeric,
is_variable boolean,
age_million_years integer
);
--
-- Name: star_star_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.star_star_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: star_star_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.star_star_id_seq OWNED BY public.star.star_id;
--
-- Name: galaxy galaxy_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy ALTER COLUMN galaxy_id SET DEFAULT nextval('public.galaxy_galaxy_id_seq'::regclass);
--
-- Name: galaxy_type galaxy_type_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy_type ALTER COLUMN galaxy_type_id SET DEFAULT nextval('public.galaxy_type_galaxy_type_id_seq'::regclass);
--
-- Name: moon moon_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.moon ALTER COLUMN moon_id SET DEFAULT nextval('public.moon_moon_id_seq'::regclass);
--
-- Name: planet planet_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.planet ALTER COLUMN planet_id SET DEFAULT nextval('public.planet_planet_id_seq'::regclass);
--
-- Name: star star_id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.star ALTER COLUMN star_id SET DEFAULT nextval('public.star_star_id_seq'::regclass);
--
-- Data for Name: galaxy; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.galaxy (galaxy_id, name, galaxy_type_id, distance_from_earth, has_dark_matter, diameter_light_years) FROM stdin;
1 Milky Way 1 0 t 105700
2 Andromeda 1 2537000 t 220000
3 Triangulum 1 2723000 t 60000
4 Whirlpool 1 23160000 t 76000
5 Cartwheel 3 500000000 t 150000
6 Sombrero 4 29350000 t 50000
\.
--
-- Data for Name: galaxy_type; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.galaxy_type (galaxy_type_id, name, description) FROM stdin;
1 Spiral A galaxy with a flat, rotating disk containing stars, gas and dust, and a central concentration of stars
2 Elliptical A galaxy with an ellipsoidal shape and a smooth, nearly featureless brightness profile
3 Irregular A galaxy that does not have a distinct regular shape
4 Lenticular A galaxy intermediate between elliptical and spiral galaxies
\.
--
-- Data for Name: moon; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.moon (moon_id, name, planet_id, has_atmosphere, diameter_km, discovery_year) FROM stdin;
1 The Moon 3 f 3474.8 \N
2 Phobos 4 f 22.2 1877
3 Deimos 4 f 12.4 1877
4 Io 5 f 3643.2 1610
5 Europa 5 f 3121.6 1610
6 Ganymede 5 t 5268.2 1610
7 Callisto 5 f 4820.6 1610
8 Amalthea 5 f 167 1892
9 Titan 6 t 5149.5 1655
10 Rhea 6 f 1527 1672
11 Iapetus 6 f 1469 1671
12 Dione 6 f 1123 1684
13 Tethys 6 f 1062 1684
14 Enceladus 6 f 504 1789
15 Titania 7 f 1578 1787
16 Oberon 7 f 1523 1787
17 Umbriel 7 f 1169 1851
18 Ariel 7 f 1158 1851
19 Miranda 7 f 471 1948
20 Triton 8 t 2706.8 1846
21 Nereid 8 f 340 1949
\.
--
-- Data for Name: planet; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.planet (planet_id, name, star_id, has_rings, orbital_period_days, moons_count) FROM stdin;
1 Mercury 1 f 88 0
2 Venus 1 f 224.7 0
3 Earth 1 f 365.25 1
4 Mars 1 f 687 2
5 Jupiter 1 t 4331 4
6 Saturn 1 t 10747 5
7 Uranus 1 t 30589 3
8 Neptune 1 t 59800 2
9 Proxima b 6 f 11.2 0
10 Sirius Ab 2 f 300 0
11 Rigel b 4 f 500 0
12 Centauri Bb 5 f 3.2 0
\.
--
-- Data for Name: star; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.star (star_id, name, galaxy_id, mass_solar_masses, is_variable, age_million_years) FROM stdin;
1 Sun 1 1.0 f 4600
2 Sirius 1 2.02 f 242
3 Betelgeuse 1 16.5 t 10
4 Rigel 1 21 t 8
5 Alpha Centauri A 1 1.1 f 4850
6 Proxima Centauri 1 0.12 t 4850
\.
--
-- Name: galaxy_galaxy_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.galaxy_galaxy_id_seq', 6, true);
--
-- Name: galaxy_type_galaxy_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.galaxy_type_galaxy_type_id_seq', 4, true);
--
-- Name: moon_moon_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.moon_moon_id_seq', 21, true);
--
-- Name: planet_planet_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.planet_planet_id_seq', 12, true);
--
-- Name: star_star_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.star_star_id_seq', 6, true);
--
-- Name: galaxy galaxy_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy
ADD CONSTRAINT galaxy_name_key UNIQUE (name);
--
-- Name: galaxy galaxy_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy
ADD CONSTRAINT galaxy_pkey PRIMARY KEY (galaxy_id);
--
-- Name: galaxy_type galaxy_type_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy_type
ADD CONSTRAINT galaxy_type_name_key UNIQUE (name);
--
-- Name: galaxy_type galaxy_type_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy_type
ADD CONSTRAINT galaxy_type_pkey PRIMARY KEY (galaxy_type_id);
--
-- Name: moon moon_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.moon
ADD CONSTRAINT moon_name_key UNIQUE (name);
--
-- Name: moon moon_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.moon
ADD CONSTRAINT moon_pkey PRIMARY KEY (moon_id);
--
-- Name: planet planet_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.planet
ADD CONSTRAINT planet_name_key UNIQUE (name);
--
-- Name: planet planet_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.planet
ADD CONSTRAINT planet_pkey PRIMARY KEY (planet_id);
--
-- Name: star star_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.star
ADD CONSTRAINT star_name_key UNIQUE (name);
--
-- Name: star star_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.star
ADD CONSTRAINT star_pkey PRIMARY KEY (star_id);
--
-- Name: galaxy galaxy_galaxy_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.galaxy
ADD CONSTRAINT galaxy_galaxy_type_id_fkey FOREIGN KEY (galaxy_type_id) REFERENCES public.galaxy_type(galaxy_type_id);
--
-- Name: moon moon_planet_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.moon
ADD CONSTRAINT moon_planet_id_fkey FOREIGN KEY (planet_id) REFERENCES public.planet(planet_id);
--
-- Name: planet planet_star_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.planet
ADD CONSTRAINT planet_star_id_fkey FOREIGN KEY (star_id) REFERENCES public.star(star_id);
--
-- Name: star star_galaxy_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.star
ADD CONSTRAINT star_galaxy_id_fkey FOREIGN KEY (galaxy_id) REFERENCES public.galaxy(galaxy_id);
--
-- PostgreSQL database dump complete
--
Evidence tier: Existing evidence
Salon appointment scheduler: salon.sql
Evidence tier: Existing evidence · drawn from the file
3 tables · 2 foreign keys · 9 columns
salon.sql: 3 tables and 2 foreign keys, read from the file when this site was built. Each line joins a foreign-key column (○) to the column it references (●). PK primary key, FK foreign key, UQ unique.Tables, columns and keys as text
appointments
| Column | Type | Not null | Keys |
|---|---|---|---|
appointment_id | integer | yes | primary key |
customer_id | integer | yes | foreign key |
service_id | integer | yes | foreign key |
time | character varying(20) | yes | – |
customers
| Column | Type | Not null | Keys |
|---|---|---|---|
customer_id | integer | yes | primary key |
phone | character varying(20) | yes | unique |
name | character varying(50) | yes | – |
services
| Column | Type | Not null | Keys |
|---|---|---|---|
service_id | integer | yes | primary key |
name | character varying(50) | yes | – |
Foreign keys
| Column | References |
|---|---|
appointments.customer_id | customers.customer_id |
appointments.service_id | services.service_id |
Show the whole file (267 lines)
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.22 (Ubuntu 12.22-0ubuntu0.20.04.4)
-- Dumped by pg_dump version 12.22 (Ubuntu 12.22-0ubuntu0.20.04.4)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
DROP DATABASE salon;
--
-- Name: salon; Type: DATABASE; Schema: -; Owner: freecodecamp
--
CREATE DATABASE salon WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';
ALTER DATABASE salon OWNER TO freecodecamp;
\connect salon
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: appointments; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.appointments (
appointment_id integer NOT NULL,
customer_id integer NOT NULL,
service_id integer NOT NULL,
"time" character varying(20) NOT NULL
);
ALTER TABLE public.appointments OWNER TO freecodecamp;
--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
CREATE SEQUENCE public.appointments_appointment_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.appointments_appointment_id_seq OWNER TO freecodecamp;
--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--
ALTER SEQUENCE public.appointments_appointment_id_seq OWNED BY public.appointments.appointment_id;
--
-- Name: customers; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.customers (
customer_id integer NOT NULL,
phone character varying(20) NOT NULL,
name character varying(50) NOT NULL
);
ALTER TABLE public.customers OWNER TO freecodecamp;
--
-- Name: customers_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
CREATE SEQUENCE public.customers_customer_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.customers_customer_id_seq OWNER TO freecodecamp;
--
-- Name: customers_customer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--
ALTER SEQUENCE public.customers_customer_id_seq OWNED BY public.customers.customer_id;
--
-- Name: services; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.services (
service_id integer NOT NULL,
name character varying(50) NOT NULL
);
ALTER TABLE public.services OWNER TO freecodecamp;
--
-- Name: services_service_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
CREATE SEQUENCE public.services_service_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.services_service_id_seq OWNER TO freecodecamp;
--
-- Name: services_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--
ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;
--
-- Name: appointments appointment_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.appointments ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointments_appointment_id_seq'::regclass);
--
-- Name: customers customer_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.customers ALTER COLUMN customer_id SET DEFAULT nextval('public.customers_customer_id_seq'::regclass);
--
-- Name: services service_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--
ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);
--
-- Data for Name: appointments; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--
--
-- Data for Name: customers; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--
--
-- Data for Name: services; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--
INSERT INTO public.services VALUES (1, 'cut');
INSERT INTO public.services VALUES (2, 'color');
INSERT INTO public.services VALUES (3, 'perm');
INSERT INTO public.services VALUES (4, 'style');
INSERT INTO public.services VALUES (5, 'trim');
--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--
SELECT pg_catalog.setval('public.appointments_appointment_id_seq', 6, true);
--
-- Name: customers_customer_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--
SELECT pg_catalog.setval('public.customers_customer_id_seq', 5, true);
--
-- Name: services_service_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--
SELECT pg_catalog.setval('public.services_service_id_seq', 5, true);
--
-- Name: appointments appointments_pkey; Type: 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);
--
-- PostgreSQL database dump complete
--
Evidence tier: Existing evidence
Queries
The salon script sends its SQL to PostgreSQL through psql: 6 statements (SELECT, INSERT) in these lines, from listing the services to booking the appointment.
The statements, in order
Evidence tier: Existing evidence
- line 14
SELECT service_id, name FROM services ORDER BY service_id - line 31
SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED - line 42
SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE' - line 47
INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME') - line 51
SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE' - line 57
INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')
Course exercise: user input goes straight into the SQL string; production code would use parameterised queries.
SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
echo "$SERVICES" | while read SERVICE_ID BAR NAME
do
if [[ -n $SERVICE_ID ]]
then
echo "$SERVICE_ID) $NAME"
fi
done
read SERVICE_ID_SELECTED
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
then
MAIN_MENU "I could not find that service. What would you like today?"
return
fi
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
if [[ -z $SERVICE_NAME ]]
then
MAIN_MENU "I could not find that service. What would you like today?"
return
fi
SERVICE_NAME=$(echo $SERVICE_NAME | sed -E 's/^ *| *$//g')
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
if [[ -z $CUSTOMER_NAME ]]
then
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
CUSTOMER_NAME=$(echo $CUSTOMER_NAME | sed -E 's/^ *| *$//g')
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
CUSTOMER_ID=$(echo $CUSTOMER_ID | sed -E 's/^ *| *$//g')
echo -e "\nWhat time would you like your $SERVICE_NAME, $CUSTOMER_NAME?"
read SERVICE_TIME
INSERT_APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")
Evidence tier: Existing evidence
Evidence
The two Relational Database certifications (an exam, and a certification with 5 projects) and the two public repositories the files above come from.
Certificates
Relational Database
Evidence tier: Existing evidence
Relational Database V8
Evidence tier: Existing evidence
Repositories
celestial-bodies-database
Evidence tier: Existing evidence
salon-appointment-scheduler
Evidence tier: Existing evidence