add more check constraints
This commit is contained in:
parent
16ff759879
commit
0f99098de5
|
@ -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")
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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")
|
||||
);
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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" (
|
||||
|
|
Loading…
Reference in New Issue