use playerstints table for foreign keys

This commit is contained in:
Nick Griffey 2024-01-29 21:37:11 -06:00
parent 460604fc49
commit 6d4e593065
1 changed files with 10 additions and 11 deletions

View File

@ -191,8 +191,8 @@ CREATE TABLE IF NOT EXISTS "batting" (
"SH" NUMERIC, "SH" NUMERIC,
"SF" NUMERIC, "SF" NUMERIC,
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"), PRIMARY KEY("player","year","stint"),
foreign key("year","player","team") references "appearances"("year","player","team") foreign key("year","player","stint") references "playerstints"("year","player","stint")
); );
insert into batting select distinct * from "transformed"."batting"; insert into batting select distinct * from "transformed"."batting";
@ -215,8 +215,8 @@ CREATE TABLE IF NOT EXISTS "fielding" (
"SB" NUMERIC, "SB" NUMERIC,
"CS" NUMERIC, "CS" NUMERIC,
"ZR" NUMERIC, "ZR" NUMERIC,
PRIMARY KEY("player","year","stint","team","POS"), PRIMARY KEY("player","year","stint","POS"),
foreign key("year","player","team") references "appearances"("year","player","team") foreign key("year","player","stint") references "playerstints"("year","player","stint")
); );
insert into fielding select distinct * from "transformed"."fielding"; insert into fielding select distinct * from "transformed"."fielding";
@ -251,8 +251,8 @@ CREATE TABLE IF NOT EXISTS "pitching" (
"SH" NUMERIC, "SH" NUMERIC,
"SF" NUMERIC, "SF" NUMERIC,
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"), PRIMARY KEY("player","year","stint"),
foreign key("year","player","team") references "appearances"("year","player","team") foreign key("year","player","stint") references "playerstints"("year","player","stint")
); );
insert into pitching select distinct * from "transformed"."pitching"; insert into pitching select distinct * from "transformed"."pitching";
@ -335,8 +335,8 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
"SB" NUMERIC, "SB" NUMERIC,
"CS" NUMERIC, "CS" NUMERIC,
"ZR" NUMERIC, "ZR" NUMERIC,
PRIMARY KEY("player","year","stint","team","POS"), PRIMARY KEY("player","year","stint","POS"),
foreign key("year","player","team") references "appearances"("year","player","team") foreign key("year","player","stint") references "playerstints"("year","player","stint")
); );
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit"; insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
@ -492,9 +492,8 @@ CREATE TABLE IF NOT EXISTS "fieldingof" (
"Glf" NUMERIC, "Glf" NUMERIC,
"Gcf" NUMERIC, "Gcf" NUMERIC,
"Grf" NUMERIC, "Grf" NUMERIC,
PRIMARY KEY("player","year","stint") PRIMARY KEY("player","year","stint"),
foreign key("player") references "people"("ID"), foreign key("year","player","stint") references "playerstints"("year","player","stint")
foreign key("year") references "seasons"("year")
); );
insert into fieldingof select distinct * from "transformed"."fieldingof"; insert into fieldingof select distinct * from "transformed"."fieldingof";