move hall of fame tables

This commit is contained in:
Nick Griffey 2024-01-28 19:07:59 -06:00
parent dfd2b78fb2
commit 8583b6332f
5 changed files with 36 additions and 27 deletions

View File

@ -9,7 +9,7 @@ baseball.db: baseball-transformed.db sql/load.sql
cat sql/load.sql | sqlite3 baseball.db cat sql/load.sql | sqlite3 baseball.db
sqlite3 baseball.db "VACUUM" 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 rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 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/appearancespost.sql | sqlite3 baseball-transformed.db
cat sql/awardsshareplayers.sql | sqlite3 baseball-transformed.db cat sql/awardsshareplayers.sql | sqlite3 baseball-transformed.db
cat sql/yearlyawards.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: baseball-raw.db:
rm -f baseball-raw.db rm -f baseball-raw.db

View File

@ -6,4 +6,8 @@ where ballots = '' or ballots = 'NA';
update halloffame update halloffame
set needed = null set needed = null
where needed = '' or needed = 'NA'; 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; commit;

View File

@ -1,18 +1,14 @@
begin; begin;
attach database 'baseball-raw.db' as 'raw';
create table if not exists "halloffamereqs" ( create table if not exists "halloffamereqs" (
"yearID" numeric, "yearID" numeric,
"votedBy" text, "votedBy" text,
"ballots" numeric, "ballots" numeric,
"needed" numeric, "needed" numeric,
"needed_note" text, "needed_note" text
primary key("yearID","votedBy")
); );
insert into halloffamereqs insert into halloffamereqs
select distinct yearid, votedby, ballots, needed, "needed_note" select distinct yearid, votedby, ballots, needed, "needed_note"
from halloffame; from "raw".halloffame;
alter table halloffame drop column "ballots";
alter table halloffame drop column "needed";
alter table halloffame drop column "needed_note";
commit; commit;

View File

@ -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;

View File

@ -539,4 +539,30 @@ create table if not exists "yearlyawards" (
); );
insert into yearlyawards select distinct * from "transformed"."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; COMMIT;