add schools table

This commit is contained in:
Nick Griffey 2024-01-27 19:27:51 -06:00
parent 7ed54099e4
commit def464ce0a
3 changed files with 38 additions and 26 deletions

View File

@ -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/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql
rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 baseball-transformed.db
@ -18,6 +18,7 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/f
cat sql/seasons.sql | sqlite3 baseball-transformed.db
cat sql/parks.sql | sqlite3 baseball-transformed.db
cat sql/collegeplaying.sql | sqlite3 baseball-transformed.db
cat sql/schools.sql | sqlite3 baseball-transformed.db
baseball-raw.db:
rm -f baseball-raw.db

View File

@ -10,22 +10,22 @@ insert into awards
select distinct * from "transformed"."awards";
CREATE TABLE IF NOT EXISTS "franchises" (
"franchID" TEXT,
"franchName" TEXT,
"ID" TEXT,
"name" TEXT,
"active" TEXT,
"NAassoc" TEXT,
PRIMARY KEY("franchID")
PRIMARY KEY("ID")
);
insert into franchises
select distinct * from "transformed"."franchises";
create table if not exists "franchiseseasons" (
"yearID" NUMERIC,
"lgID" TEXT,
"teamID" TEXT,
"franchID" TEXT,
"divID" TEXT,
"year" NUMERIC,
"league" TEXT,
"team" TEXT,
"franchise" TEXT,
"division" TEXT,
"Rank" NUMERIC,
"G" NUMERIC,
"Ghome" NUMERIC,
@ -69,9 +69,9 @@ create table if not exists "franchiseseasons" (
"teamIDBR" TEXT,
"teamIDlahman45" TEXT,
"teamIDretro" TEXT,
PRIMARY KEY("yearID","franchID"),
foreign key("yearID") references "seasons"("year"),
foreign key("franchID") references "franchises"("ID")
PRIMARY KEY("year","franchise"),
foreign key("year") references "seasons"("year"),
foreign key("franchise") references "franchises"("ID")
);
insert into franchiseseasons
@ -86,7 +86,7 @@ insert into seasons
select distinct * from "transformed"."seasons";
CREATE TABLE "people" (
"playerID" text,
"ID" text,
"birthYear" NUMERIC,
"birthMonth" NUMERIC,
"birthDay" NUMERIC,
@ -110,39 +110,50 @@ CREATE TABLE "people" (
"finalGame" text,
"retroID" text,
"bbrefID" text,
primary key("playerID")
primary key("ID")
);
INSERT INTO "people" SELECT DISTINCT * FROM "transformed"."people";
CREATE TABLE IF NOT EXISTS "parks" (
"park.key" TEXT,
"park.name" TEXT,
"ID" TEXT,
"name" TEXT,
"city" TEXT,
"state" TEXT,
"country" TEXT,
PRIMARY KEY("park.key")
PRIMARY KEY("ID")
);
insert into "parks" select distinct * from "transformed"."parks";
CREATE TABLE IF NOT EXISTS "parkaliases" (
"ID" TEXT,
"park" TEXT,
"alias" TEXT,
PRIMARY KEY("ID","alias"),
foreign key("ID") references "parks"("park.key")
PRIMARY KEY("park","alias"),
foreign key("park") references "parks"("ID")
);
insert into "parkaliases" select distinct * from "transformed"."parkaliases";
CREATE TABLE IF NOT EXISTS "collegeplaying" (
"playerID" TEXT,
"schoolID" TEXT,
"yearID" NUMERIC,
PRIMARY KEY("playerID","yearID","schoolID"),
foreign key("playerID") references "people"("playerID"),
foreign key("schoolID") references "schools"("schoolID")
"player" TEXT,
"school" TEXT,
"year" NUMERIC,
PRIMARY KEY("player","year","school"),
foreign key("player") references "people"("ID"),
foreign key("school") references "schools"("ID")
);
insert into collegeplaying select distinct * from "transformed"."collegeplaying";
CREATE TABLE IF NOT EXISTS "schools" (
"ID" TEXT,
"name_full" TEXT,
"city" TEXT,
"state" TEXT,
"country" TEXT,
PRIMARY KEY("ID")
);
insert into schools select distinct * from "transformed"."schools";
COMMIT;