diff --git a/Makefile b/Makefile index dca25fa..b696a03 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ baseball.db: baseball-transformed.db sql/load.sql cat sql/load.sql | sqlite3 baseball.db sqlite3 baseball.db "VACUUM" -baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql sql/leagues.sql sql/managers.sql sql/awardsmanagers.sql sql/battingpost.sql sql/fieldingpost.sql sql/pitchingpost.sql sql/appearancespost.sql sql/awardsshareplayers.sql sql/yearlyawards.sql +baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql sql/leagues.sql sql/managers.sql sql/awardsmanagers.sql sql/battingpost.sql sql/fieldingpost.sql sql/pitchingpost.sql sql/appearancespost.sql sql/awardsshareplayers.sql sql/yearlyawards.sql sql/halloffame.sql sql/halloffamereqs.sql rm -f baseball-transformed.db cp baseball-raw.db baseball-transformed.db cat sql/franchises.sql | sqlite3 baseball-transformed.db @@ -38,6 +38,8 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/t cat sql/appearancespost.sql | sqlite3 baseball-transformed.db cat sql/awardsshareplayers.sql | sqlite3 baseball-transformed.db cat sql/yearlyawards.sql | sqlite3 baseball-transformed.db + cat sql/halloffame.sql | sqlite3 baseball-transformed.db + cat sql/halloffamereqs.sql | sqlite3 baseball-transformed.db baseball-raw.db: rm -f baseball-raw.db diff --git a/sql/corrections/halloffame.sql b/sql/halloffame.sql similarity index 53% rename from sql/corrections/halloffame.sql rename to sql/halloffame.sql index eb45176..abc8997 100644 --- a/sql/corrections/halloffame.sql +++ b/sql/halloffame.sql @@ -6,4 +6,8 @@ where ballots = '' or ballots = 'NA'; update halloffame set needed = null where needed = '' or needed = 'NA'; + +alter table halloffame drop column "ballots"; +alter table halloffame drop column "needed"; +alter table halloffame drop column "needed_note"; commit; diff --git a/sql/2nf/halloffame.sql b/sql/halloffamereqs.sql similarity index 52% rename from sql/2nf/halloffame.sql rename to sql/halloffamereqs.sql index 82c9715..6cf4843 100644 --- a/sql/2nf/halloffame.sql +++ b/sql/halloffamereqs.sql @@ -1,18 +1,14 @@ begin; +attach database 'baseball-raw.db' as 'raw'; create table if not exists "halloffamereqs" ( "yearID" numeric, "votedBy" text, "ballots" numeric, "needed" numeric, - "needed_note" text, - primary key("yearID","votedBy") + "needed_note" text ); insert into halloffamereqs select distinct yearid, votedby, ballots, needed, "needed_note" -from halloffame; - -alter table halloffame drop column "ballots"; -alter table halloffame drop column "needed"; -alter table halloffame drop column "needed_note"; +from "raw".halloffame; commit; diff --git a/sql/keys/halloffame.sql b/sql/keys/halloffame.sql deleted file mode 100644 index ba2d305..0000000 --- a/sql/keys/halloffame.sql +++ /dev/null @@ -1,19 +0,0 @@ -BEGIN; -CREATE TABLE IF NOT EXISTS "pk_halloffame" ( - "playerID" TEXT, - "yearID" NUMERIC, - "votedBy" TEXT, - "ballots" NUMERIC, - "needed" NUMERIC, - "votes" NUMERIC, - "inducted" TEXT, - "category" TEXT, - "needed_note" TEXT, - PRIMARY KEY("playerID","yearID","votedBy") - foreign key("playerID") references "people"("playerID") -); - -INSERT INTO "pk_halloffame" SELECT DISTINCT * FROM "halloffame"; -DROP TABLE "halloffame"; -ALTER TABLE "pk_halloffame" RENAME TO "halloffame"; -COMMIT; diff --git a/sql/load.sql b/sql/load.sql index 5fcd9cf..9213a46 100644 --- a/sql/load.sql +++ b/sql/load.sql @@ -539,4 +539,30 @@ create table if not exists "yearlyawards" ( ); insert into yearlyawards select distinct * from "transformed"."yearlyawards"; + +CREATE TABLE IF NOT EXISTS "halloffame" ( + "player" TEXT, + "year" NUMERIC, + "votedBy" TEXT, + "votes" NUMERIC, + "inducted" TEXT, + "category" TEXT, + PRIMARY KEY("player","year","votedBy") + foreign key("player") references "people"("ID"), + foreign key("year","votedBy") references "halloffamereqs"("year","votedBy") +); + +insert into halloffame select distinct * from "transformed".halloffame; + +create table if not exists "halloffamereqs" ( + "year" numeric, + "votedBy" text, + "ballots" numeric, + "needed" numeric, + "needed_note" text, + primary key("year","votedBy"), + foreign key("year") references "seasons"("year") +); + +insert into halloffamereqs select distinct * from "transformed".halloffamereqs; COMMIT;