Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate data and schema generation #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
log_file = /tmp/sakila-postgresql-session.log
tables = earthquake female_names last_names male_names songs
only_data_dir = data/without-headers

$(tables): %: data/%.csv
mkdir -p $(only_data_dir)
tail -n +2 $< > $(only_data_dir)/[email protected]
psql -c "\copy $@ FROM $(only_data_dir)/[email protected] delimiter ',' csv"

build: src/ddl/schema.sql
psql --quiet --log-file=$(log_file) < $<

install: $(tables)
rm -rf $(only_data_dir)

uninstall: src/ddl/delete-data.sql
psql --quiet --log-file=$(log_file) < $<

clean: src/ddl/drop-objects.sql
psql --quiet --log-file=$(log_file) < $<
File renamed without changes.
3 changes: 2 additions & 1 deletion female_names.csv → data/female_names.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,word
1,Emma
2,Olivia
3,Ava
Expand Down Expand Up @@ -997,4 +998,4 @@
997,Miya
998,Monserrat
999,Zendaya
1000,Alora
1000,Alora
13 changes: 7 additions & 6 deletions last_names.csv → data/last_names.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,word
1,Smith
2,Johnson
3,Williams
Expand Down Expand Up @@ -474,7 +475,7 @@
474,Wolf
475,Valencia
476,Franco
476,Saunders
477,Saunders
478,Rowe
479,Gallagher
480,Farmer
Expand Down Expand Up @@ -576,10 +577,10 @@
576,Holloway
577,Lozano
578,Flowers
578,Rangel
579,Rangel
580,Hoover
581,Arias
581,Short
582,Short
583,Mora
584,Valenzuela
585,Bryan
Expand Down Expand Up @@ -672,7 +673,7 @@
672,Shields
673,Rubio
674,Choi
674,Huffman
675,Huffman
676,Boyer
677,Garrison
678,Arroyo
Expand Down Expand Up @@ -772,7 +773,7 @@
772,Leach
773,Meadows
774,Davila
774,Orr
775,Orr
776,Whitehead
777,Pruitt
778,Kent
Expand Down Expand Up @@ -981,7 +982,7 @@
981,Good
982,Madden
983,Mccann
983,Terrell
984,Terrell
985,Jarvis
986,Dickson
987,Reyna
Expand Down
3 changes: 2 additions & 1 deletion male_names.csv → data/male_names.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,names
1,Liam
2,Noah
3,William
Expand Down Expand Up @@ -997,4 +998,4 @@
997,Ramiro
998,Yisroel
999,Howard
1000,Jaxx
1000,Jaxx
File renamed without changes.
10,051 changes: 0 additions & 10,051 deletions song.sql

This file was deleted.

5 changes: 5 additions & 0 deletions src/ddl/delete-data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DELETE FROM earthquake;
DELETE FROM songs;
DELETE FROM male_names;
DELETE FROM female_names;
DELETE FROM last_names;
5 changes: 5 additions & 0 deletions src/ddl/drop-objects.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE songs;
DROP TABLE earthquake;
DROP TABLE male_names;
DROP TABLE female_names;
DROP TABLE last_names;
43 changes: 43 additions & 0 deletions src/ddl/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- songs
CREATE TABLE songs (
song_id integer,
title character varying,
artist character varying,
album character varying,
year_released integer,
duration numeric,
tempo numeric,
loudness numeric
);

-- earthquakes
CREATE TABLE earthquake (
earthquake_id BIGSERIAL PRIMARY KEY,
occured_on TIMESTAMP,
latitude DECIMAL,
longitude DECIMAL,
depth DECIMAL,
magnitude DECIMAL,
calculation VARCHAR(29),
network_id VARCHAR(29),
place VARCHAR(203),
cause VARCHAR(57)
);

-- male_names
CREATE TABLE male_names (
id BIGSERIAL PRIMARY KEY,
word VARCHAR(29)
);

-- female_names
CREATE TABLE female_names (
id BIGSERIAL PRIMARY KEY,
word VARCHAR(29)
);

-- last_names
CREATE TABLE last_names (
id BIGSERIAL PRIMARY KEY,
word VARCHAR(29)
);