diff --git a/sql/allstars.sql b/sql/allstars.sql index 9a2a1c5..0db6742 100644 --- a/sql/allstars.sql +++ b/sql/allstars.sql @@ -53,7 +53,7 @@ create table if not exists "allstars" ( "year" text, "gameNum" text, "team" text, - "GP" numeric, + "GP" numeric check ("GP" in (0, 1)), primary key("player","year","gameNum"), foreign key("year","gameNum") references "allstargames"("year","gameNum"), foreign key("player","year","team") references "appearances"("player","year","team") diff --git a/sql/allstarstartingpos.sql b/sql/allstarstartingpos.sql index 12086f2..baf86b1 100644 --- a/sql/allstarstartingpos.sql +++ b/sql/allstarstartingpos.sql @@ -43,7 +43,7 @@ CREATE TABLE "allstarstartingpos" ( "year" NUMERIC, "gameNum" NUMERIC, "league" NUMERIC, - "startingPos" NUMERIC, + "startingPos" NUMERIC check ("startingPos" in (1,2,3,4,5,6,7,8,9,10)), primary key("year","gameNum","league","startingPos"), unique("year","gameNum","league","startingPos"), foreign key("player","year","gameNum") references "allstars"("player","year","gameNum"), diff --git a/sql/awardssharemanagers.sql b/sql/awardssharemanagers.sql index 68da9c3..89f895a 100644 --- a/sql/awardssharemanagers.sql +++ b/sql/awardssharemanagers.sql @@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS "awardssharemanagers" ( "year" NUMERIC, "league" TEXT, "manager" TEXT, - "pointsWon" NUMERIC check (pointsWon <= pointsMax), + "pointsWon" NUMERIC check (pointsWon <= pointsMax), "pointsMax" NUMERIC, "votesFirst" NUMERIC, PRIMARY KEY("manager","award","year","league"), diff --git a/sql/awardsshareplayers.sql b/sql/awardsshareplayers.sql index ef7837e..b14c34f 100644 --- a/sql/awardsshareplayers.sql +++ b/sql/awardsshareplayers.sql @@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS main."awardsshareplayers" ( "year" NUMERIC, "league" TEXT, "player" TEXT, - "pointsWon" NUMERIC check (pointsWon <= pointsMax), + "pointsWon" NUMERIC check (pointsWon <= pointsMax), "pointsMax" NUMERIC, "votesFirst" NUMERIC, PRIMARY KEY("award","year","player","league"), diff --git a/sql/franchises.sql b/sql/franchises.sql index d0ef528..40a7b08 100644 --- a/sql/franchises.sql +++ b/sql/franchises.sql @@ -6,10 +6,14 @@ attach database 'baseball-raw.db' as 'raw'; create temp table franchises as select * from "raw".teamsfranchises; +update franchises +set active = 'N' +where active = 'NA'; + CREATE TABLE IF NOT EXISTS main."franchises" ( "ID" TEXT, "name" TEXT, - "active" TEXT, + "active" TEXT check ("active" in ('Y','N')), "NAassoc" TEXT, PRIMARY KEY("ID") ); diff --git a/sql/halloffame.sql b/sql/halloffame.sql index 772f09d..7ad7e61 100644 --- a/sql/halloffame.sql +++ b/sql/halloffame.sql @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS main."halloffame" ( "year" NUMERIC, "votedBy" TEXT, "votes" NUMERIC, - "inducted" TEXT, + "inducted" TEXT check ("inducted" in ('Y','N')), "category" TEXT, PRIMARY KEY("player","year","votedBy") foreign key("player") references "people"("ID"), diff --git a/sql/halloffamereqs.sql b/sql/halloffamereqs.sql index 843d323..9c0524a 100644 --- a/sql/halloffamereqs.sql +++ b/sql/halloffamereqs.sql @@ -14,11 +14,19 @@ insert into halloffamereqs select distinct yearid, votedby, ballots, needed, "needed_note" from "raw".halloffame; +update halloffamereqs +set ballots = null +where ballots = ""; + +update halloffamereqs +set needed = null +where needed = ""; + create table if not exists main."halloffamereqs" ( "year" numeric, "votedBy" text, "ballots" numeric, - "needed" numeric, + "needed" numeric check ("needed" <= "ballots"), "needed_note" text, primary key("year","votedBy"), foreign key("year") references "seasons"("year") diff --git a/sql/homegames.sql b/sql/homegames.sql index 1e60b05..d0d0fd6 100644 --- a/sql/homegames.sql +++ b/sql/homegames.sql @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS main."homegames" ( "year" NUMERIC, "team" TEXT, "park" TEXT, - "first" TEXT check(unixepoch("first") <= unixepoch("last")), + "first" TEXT check(unixepoch("first") <= unixepoch("last")), "last" TEXT, "games" NUMERIC, "openings" NUMERIC, diff --git a/sql/teamseasons.sql b/sql/teamseasons.sql index c1cc0be..1450c9c 100644 --- a/sql/teamseasons.sql +++ b/sql/teamseasons.sql @@ -14,6 +14,22 @@ update teamseasons set teamid = 'PHP' where teamid = 'PH4' and franchid = 'PHQ'; +update teamseasons +set divwin = null +where divwin = ''; + +update teamseasons +set wcwin = null +where wcwin = ''; + +update teamseasons +set lgwin = null +where lgwin = ''; + +update teamseasons +set wswin = null +where wswin = ''; + alter table "teamseasons" drop column "franchID"; create table if not exists main."teamseasons" (