use appearances as parent for foreign key constraints

This commit is contained in:
Nick Griffey 2024-01-27 22:28:49 -06:00
parent eb489be084
commit 6bc8d4e9e9
1 changed files with 5 additions and 10 deletions

View File

@ -163,8 +163,7 @@ CREATE TABLE IF NOT EXISTS "salaries" (
"player" TEXT,
"salary" NUMERIC,
PRIMARY KEY("year","player","team"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
foreign key("year","player","team") references "appearances"("year","player","team")
);
insert into salaries select distinct * from "transformed"."salaries";
@ -192,8 +191,7 @@ CREATE TABLE IF NOT EXISTS "batting" (
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
foreign key("year","player","team") references "appearances"("year","player","team")
);
insert into batting select distinct * from "transformed"."batting";
@ -217,8 +215,7 @@ CREATE TABLE IF NOT EXISTS "fielding" (
"CS" NUMERIC,
"ZR" NUMERIC,
PRIMARY KEY("player","year","stint","team","POS"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
foreign key("year","player","team") references "appearances"("year","player","team")
);
insert into fielding select distinct * from "transformed"."fielding";
@ -254,8 +251,7 @@ CREATE TABLE IF NOT EXISTS "pitching" (
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
foreign key("year","player","team") references "appearances"("year","player","team")
);
insert into pitching select distinct * from "transformed"."pitching";
@ -339,8 +335,7 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
"CS" NUMERIC,
"ZR" NUMERIC,
PRIMARY KEY("player","year","stint","team","POS"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
foreign key("year","player","team") references "appearances"("year","player","team")
);
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";