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