Setup Makefile and create and insert scripts

main
Jeffrey Elkner 2 years ago
parent 7adfeab61f
commit b2559a5dc5

2
.gitignore vendored

@ -0,0 +1,2 @@
.pgenv*
.*.sw*

@ -0,0 +1,17 @@
SCRIPTS = $(CURDIR)/scripts
ENV_LOCAL = $(CURDIR)/.pgenv_local
ENV_REMOTE = $(CURDIR)/.pgenv_remote
MAIN = $(SCRIPTS)/create_tables.sql
IMPORT = $(SCRIPTS)/insert_data.sql
SHELL := /usr/bin/env bash
all:
@echo "Error: Please specify remote or local target!"
remote:
source $(ENV_REMOTE) && psql -h $${PGHOST} -d $${PGDATABASE} -U $${PGUSER} -f $(MAIN)
source $(ENV_REMOTE) && psql -h $${PGHOST} -d $${PGDATABASE} -U $${PGUSER} -f $(IMPORT)
local:
source $(ENV_LOCAL) && psql -h $${PGHOST} -d $${PGDATABASE} -U $${PGUSER} -f $(MAIN)
source $(ENV_LOCAL) && psql -h $${PGHOST} -d $${PGDATABASE} -U $${PGUSER} -f $(IMPORT)

@ -1,3 +1,6 @@
# horsesdb # A Database of Horses, Stables, Races, and Prizes
Another small database project for learning PostgreSQL Postgress scripts for a horses database. This idea was directly stolen from
one of my students, who deserves *all* credit for it!
## Resources

@ -0,0 +1,380 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 13.9 (Debian 13.9-0+deb11u1)
-- Dumped by pg_dump version 13.9 (Debian 13.9-0+deb11u1)
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: horses; Type: TABLE; Schema: public; Owner: jrisacher
--
CREATE TABLE public.horses (
id integer NOT NULL,
name character varying(30),
farm character varying(30),
breed character varying(50),
prize integer,
date_won date
);
ALTER TABLE public.horses OWNER TO jrisacher;
--
-- Name: horses_id_seq; Type: SEQUENCE; Schema: public; Owner: jrisacher
--
CREATE SEQUENCE public.horses_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.horses_id_seq OWNER TO jrisacher;
--
-- Name: horses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: jrisacher
--
ALTER SEQUENCE public.horses_id_seq OWNED BY public.horses.id;
--
-- Name: names; Type: TABLE; Schema: public; Owner: mmccormack
--
CREATE TABLE public.names (
place integer NOT NULL,
horses character varying(50) NOT NULL,
rider_num integer NOT NULL
);
ALTER TABLE public.names OWNER TO mmccormack;
--
-- Name: names_id_seq; Type: SEQUENCE; Schema: public; Owner: mmccormack
--
CREATE SEQUENCE public.names_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.names_id_seq OWNER TO mmccormack;
--
-- Name: names_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: mmccormack
--
ALTER SEQUENCE public.names_id_seq OWNED BY public.names.place;
--
-- Name: prizes; Type: TABLE; Schema: public; Owner: mmccormack
--
CREATE TABLE public.prizes (
place integer NOT NULL,
prize character varying(50) NOT NULL
);
ALTER TABLE public.prizes OWNER TO mmccormack;
--
-- Name: prizes_place_seq; Type: SEQUENCE; Schema: public; Owner: mmccormack
--
CREATE SEQUENCE public.prizes_place_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.prizes_place_seq OWNER TO mmccormack;
--
-- Name: prizes_place_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: mmccormack
--
ALTER SEQUENCE public.prizes_place_seq OWNED BY public.prizes.place;
--
-- Name: rider; Type: TABLE; Schema: public; Owner: jrisacher
--
CREATE TABLE public.rider (
rider_num integer NOT NULL,
name character varying(50) NOT NULL,
id integer NOT NULL
);
ALTER TABLE public.rider OWNER TO jrisacher;
--
-- Name: rider_id_seq; Type: SEQUENCE; Schema: public; Owner: jrisacher
--
CREATE SEQUENCE public.rider_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.rider_id_seq OWNER TO jrisacher;
--
-- Name: rider_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: jrisacher
--
ALTER SEQUENCE public.rider_id_seq OWNED BY public.rider.id;
--
-- Name: rider_rider_num_seq; Type: SEQUENCE; Schema: public; Owner: jrisacher
--
CREATE SEQUENCE public.rider_rider_num_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.rider_rider_num_seq OWNER TO jrisacher;
--
-- Name: rider_rider_num_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: jrisacher
--
ALTER SEQUENCE public.rider_rider_num_seq OWNED BY public.rider.rider_num;
--
-- Name: horses id; Type: DEFAULT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.horses ALTER COLUMN id SET DEFAULT nextval('public.horses_id_seq'::regclass);
--
-- Name: names place; Type: DEFAULT; Schema: public; Owner: mmccormack
--
ALTER TABLE ONLY public.names ALTER COLUMN place SET DEFAULT nextval('public.names_id_seq'::regclass);
--
-- Name: prizes place; Type: DEFAULT; Schema: public; Owner: mmccormack
--
ALTER TABLE ONLY public.prizes ALTER COLUMN place SET DEFAULT nextval('public.prizes_place_seq'::regclass);
--
-- Name: rider rider_num; Type: DEFAULT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.rider ALTER COLUMN rider_num SET DEFAULT nextval('public.rider_rider_num_seq'::regclass);
--
-- Name: rider id; Type: DEFAULT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.rider ALTER COLUMN id SET DEFAULT nextval('public.rider_id_seq'::regclass);
--
-- Data for Name: horses; Type: TABLE DATA; Schema: public; Owner: jrisacher
--
COPY public.horses (id, name, farm, breed, prize, date_won) FROM stdin;
1 calypso sleipnir stables thoroughbred 1000 2005-03-12
2 sunny sleipnir stables thoroughbred 500 2012-07-15
3 Eevee sleipnir stables paint 300 2020-12-20
4 wally Shenandoah stables Icelandic horse 300 2020-12-20
5 calypso sleipnir stables thoroughbred 800 2011-06-23
6 Inny Burgundy Farm quarer horse 1000 2007-04-04
7 calypso sleipnir stables thoroughbred 2000 2003-01-13
8 Eevee sleipnir stables paint 100 2021-03-07
9 Inny Burgundy Farm quarer horse 200 2008-03-14
10 wally Shenandoah stables Icelandic horse 400 2021-09-22
11 Virginia Marithiel Mustang 900 2001-08-17
\.
--
-- Data for Name: names; Type: TABLE DATA; Schema: public; Owner: mmccormack
--
COPY public.names (place, horses, rider_num) FROM stdin;
1 Calypso 20
2 Inny 15
3 Eevee 30
4 Inara 6
5 shlipnir 18
6 Wally 17
7 Sunny 35
8 Bullet 7
9 Virginia 22
10 Squid 54
\.
--
-- Data for Name: prizes; Type: TABLE DATA; Schema: public; Owner: mmccormack
--
COPY public.prizes (place, prize) FROM stdin;
1 $1,000
2 $950
3 $900
4 $800
5 $700
6 $600
7 $500
8 $400
9 $300
10 $200
\.
--
-- Data for Name: rider; Type: TABLE DATA; Schema: public; Owner: jrisacher
--
COPY public.rider (rider_num, name, id) FROM stdin;
20 Luke 1
15 Rowan 2
30 Dylan 3
6 libby 4
18 Mark 5
17 Owen 6
35 Kyle 7
7 Marin 8
22 Lacey 9
54 Matthew 10
\.
--
-- Name: horses_id_seq; Type: SEQUENCE SET; Schema: public; Owner: jrisacher
--
SELECT pg_catalog.setval('public.horses_id_seq', 11, true);
--
-- Name: names_id_seq; Type: SEQUENCE SET; Schema: public; Owner: mmccormack
--
SELECT pg_catalog.setval('public.names_id_seq', 8, true);
--
-- Name: prizes_place_seq; Type: SEQUENCE SET; Schema: public; Owner: mmccormack
--
SELECT pg_catalog.setval('public.prizes_place_seq', 1, false);
--
-- Name: rider_id_seq; Type: SEQUENCE SET; Schema: public; Owner: jrisacher
--
SELECT pg_catalog.setval('public.rider_id_seq', 10, true);
--
-- Name: rider_rider_num_seq; Type: SEQUENCE SET; Schema: public; Owner: jrisacher
--
SELECT pg_catalog.setval('public.rider_rider_num_seq', 1, false);
--
-- Name: horses horses_pkey; Type: CONSTRAINT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.horses
ADD CONSTRAINT horses_pkey PRIMARY KEY (id);
--
-- Name: names names_pkey; Type: CONSTRAINT; Schema: public; Owner: mmccormack
--
ALTER TABLE ONLY public.names
ADD CONSTRAINT names_pkey PRIMARY KEY (rider_num);
--
-- Name: prizes prizes_pkey; Type: CONSTRAINT; Schema: public; Owner: mmccormack
--
ALTER TABLE ONLY public.prizes
ADD CONSTRAINT prizes_pkey PRIMARY KEY (place);
--
-- Name: rider rider_pkey; Type: CONSTRAINT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.rider
ADD CONSTRAINT rider_pkey PRIMARY KEY (id);
--
-- Name: id; Type: INDEX; Schema: public; Owner: jrisacher
--
CREATE INDEX id ON public.rider USING btree (rider_num);
--
-- Name: rider rider_rider_num_fkey; Type: FK CONSTRAINT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.rider
ADD CONSTRAINT rider_rider_num_fkey FOREIGN KEY (rider_num) REFERENCES public.names(rider_num);
--
-- PostgreSQL database dump complete
--

@ -0,0 +1,105 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 13.9 (Debian 13.9-0+deb11u1)
-- Dumped by pg_dump version 13.9 (Debian 13.9-0+deb11u1)
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: horses; Type: TABLE; Schema: public; Owner: jrisacher
--
CREATE TABLE public.horses (
id integer NOT NULL,
name character varying(30),
farm character varying(30),
breed character varying(50),
prize integer,
date_won date
);
ALTER TABLE public.horses OWNER TO jrisacher;
--
-- Name: horses_id_seq; Type: SEQUENCE; Schema: public; Owner: jrisacher
--
CREATE SEQUENCE public.horses_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.horses_id_seq OWNER TO jrisacher;
--
-- Name: horses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: jrisacher
--
ALTER SEQUENCE public.horses_id_seq OWNED BY public.horses.id;
--
-- Name: horses id; Type: DEFAULT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.horses ALTER COLUMN id SET DEFAULT nextval('public.horses_id_seq'::regclass);
--
-- Data for Name: horses; Type: TABLE DATA; Schema: public; Owner: jrisacher
--
COPY public.horses (id, name, farm, breed, prize, date_won) FROM stdin;
1 calypso sleipnir stables thoroughbred 1000 2005-03-12
2 sunny sleipnir stables thoroughbred 500 2012-07-15
3 Eevee sleipnir stables paint 300 2020-12-20
4 wally Shenandoah stables Icelandic horse 300 2020-12-20
5 calypso sleipnir stables thoroughbred 800 2011-06-23
6 Inny Burgundy Farm quarer horse 1000 2007-04-04
7 calypso sleipnir stables thoroughbred 2000 2003-01-13
8 Eevee sleipnir stables paint 100 2021-03-07
9 Inny Burgundy Farm quarer horse 200 2008-03-14
10 wally Shenandoah stables Icelandic horse 400 2021-09-22
11 Virginia Marithiel Mustang 900 2001-08-17
\.
--
-- Name: horses_id_seq; Type: SEQUENCE SET; Schema: public; Owner: jrisacher
--
SELECT pg_catalog.setval('public.horses_id_seq', 11, true);
--
-- Name: horses horses_pkey; Type: CONSTRAINT; Schema: public; Owner: jrisacher
--
ALTER TABLE ONLY public.horses
ADD CONSTRAINT horses_pkey PRIMARY KEY (id);
--
-- PostgreSQL database dump complete
--

@ -0,0 +1,10 @@
(2, 'Sunny', 'Sleipnir Stables', 'thoroughbred', 500, '2012-07-15')
(3, 'Eevee', 'Sleipnir Stables', 'paint', 300, '2020-12-20')
(4, 'Wally', 'Shenandoah Stables', 'Icelandic horse', 300, '2020-12-20')
(5, 'Calypso', 'Sleipnir Stables', 'thoroughbred', 800, '2011-06-23')
(6, 'Inny', 'Burgundy Farm', 'quarter horse', 1000, '2007-04-04')
(7, 'Calypso', 'Sleipnir Stables', 'thoroughbred', 2000, '2003-01-13')
(8, 'Eevee', 'Sleipnir Stables', 'paint', 100, '2021-03-07')
(9, 'Inny', 'Burgundy Farm', 'quarter horse', 200, '2008-03-14')
(10, 'Wally', 'Shenandoah Stables', 'Icelandic horse', 400, '2021-09-22')
(11, 'Virginia', 'Marithiel', 'Mustang', 900, '2001-08-17')

@ -0,0 +1,11 @@
BEGIN TRANSACTION;
DROP TABLE IF EXISTS horses;
CREATE TABLE horses (
id SERIAL PRIMARY KEY,
name VARCHAR(30),
farm VARCHAR(30),
breed VARCHAR(50),
prize INT,
date_won DATE
);
COMMIT;

@ -0,0 +1,35 @@
BEGIN TRANSACTION;
INSERT INTO horses VALUES (
1, 'Calypso', 'Sleipnir Stables', 'thoroughbred', 1000, '2005-03-12'
);
INSERT INTO horses VALUES (
2, 'Sunny', 'Sleipnir Stables', 'thoroughbred', 500, '2012-07-15'
);
INSERT INTO horses VALUES (
3, 'Eevee', 'Sleipnir Stables', 'paint', 300, '2020-12-20'
);
INSERT INTO horses VALUES (
4, 'Wally', 'Shenandoah Stables', 'Icelandic horse', 300, '2020-12-20'
);
INSERT INTO horses VALUES (
5, 'Calypso', 'Sleipnir Stables', 'thoroughbred', 800, '2011-06-23'
);
INSERT INTO horses VALUES (
6, 'Inny', 'Burgundy Farm', 'quarter horse', 1000, '2007-04-04'
);
INSERT INTO horses VALUES (
7, 'Calypso', 'Sleipnir Stables', 'thoroughbred', 2000, '2003-01-13'
);
INSERT INTO horses VALUES (
8, 'Eevee', 'Sleipnir Stables', 'paint', 100, '2021-03-07'
);
INSERT INTO horses VALUES (
9, 'Inny', 'Burgundy Farm', 'quarter horse', 200, '2008-03-14'
);
INSERT INTO horses VALUES (
10, 'Wally', 'Shenandoah Stables', 'Icelandic horse', 400, '2021-09-22'
);
INSERT INTO horses VALUES (
11, 'Virginia', 'Marithiel', 'Mustang', 900, '2001-08-17'
);
COMMIT;
Loading…
Cancel
Save