rename table

This commit is contained in:
Nick Griffey 2024-01-27 21:41:23 -06:00
parent 67fc105f66
commit ec2a2057f2
3 changed files with 16 additions and 16 deletions

View File

@ -9,7 +9,7 @@ baseball.db: baseball-transformed.db sql/load.sql
cat sql/load.sql | sqlite3 baseball.db cat sql/load.sql | sqlite3 baseball.db
sqlite3 baseball.db "VACUUM" sqlite3 baseball.db "VACUUM"
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teamcodes.sql baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql
rm -f baseball-transformed.db rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 baseball-transformed.db cat sql/franchises.sql | sqlite3 baseball-transformed.db
@ -28,7 +28,7 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/f
cat sql/people.sql | sqlite3 baseball-transformed.db cat sql/people.sql | sqlite3 baseball-transformed.db
cat sql/seriespost.sql | sqlite3 baseball-transformed.db cat sql/seriespost.sql | sqlite3 baseball-transformed.db
cat sql/fieldingofsplit.sql | sqlite3 baseball-transformed.db cat sql/fieldingofsplit.sql | sqlite3 baseball-transformed.db
cat sql/teamcodes.sql | sqlite3 baseball-transformed.db cat sql/teams.sql | sqlite3 baseball-transformed.db
baseball-raw.db: baseball-raw.db:
rm -f baseball-raw.db rm -f baseball-raw.db

View File

@ -71,7 +71,7 @@ create table if not exists "franchiseseasons" (
"teamIDretro" TEXT, "teamIDretro" TEXT,
PRIMARY KEY("year","franchise"), PRIMARY KEY("year","franchise"),
foreign key("year") references "seasons"("year"), foreign key("year") references "seasons"("year"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("franchise") references "franchises"("ID") foreign key("franchise") references "franchises"("ID")
); );
@ -165,7 +165,7 @@ CREATE TABLE IF NOT EXISTS "salaries" (
"salary" NUMERIC, "salary" NUMERIC,
PRIMARY KEY("year","player","team"), PRIMARY KEY("year","player","team"),
foreign key("player") references "people"("ID"), foreign key("player") references "people"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS "batting" (
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"), PRIMARY KEY("player","year","stint","team"),
foreign key("player") references "people"("ID"), foreign key("player") references "people"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
@ -221,7 +221,7 @@ CREATE TABLE IF NOT EXISTS "fielding" (
"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("player") references "people"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
@ -259,7 +259,7 @@ CREATE TABLE IF NOT EXISTS "pitching" (
"GIDP" NUMERIC, "GIDP" NUMERIC,
PRIMARY KEY("player","year","stint","team"), PRIMARY KEY("player","year","stint","team"),
foreign key("player") references "people"("ID"), foreign key("player") references "people"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
@ -288,7 +288,7 @@ CREATE TABLE IF NOT EXISTS "appearances" (
"G_pr" NUMERIC, "G_pr" NUMERIC,
PRIMARY KEY("year","team","player"), PRIMARY KEY("year","team","player"),
foreign key("player") references "people"("ID"), foreign key("player") references "people"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
@ -305,7 +305,7 @@ CREATE TABLE IF NOT EXISTS "homegames" (
"attendance" NUMERIC, "attendance" NUMERIC,
PRIMARY KEY("year","team","park"), PRIMARY KEY("year","team","park"),
foreign key("park") references "parks"("ID"), foreign key("park") references "parks"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
@ -345,18 +345,18 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
"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("player") references "people"("ID"),
foreign key("team") references "teamcodes"("ID"), foreign key("team") references "teams"("ID"),
foreign key("year") references "seasons"("year") foreign key("year") references "seasons"("year")
); );
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit"; insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
create table if not exists teamcodes ( create table if not exists teams (
"ID" text, "ID" text,
"franchise" text, "franchise" text,
primary key("ID"), primary key("ID"),
foreign key("franchise") references "franchises"("ID") foreign key("franchise") references "franchises"("ID")
); );
insert into teamcodes select distinct * from "transformed"."teamcodes"; insert into teams select distinct * from "transformed"."teams";
COMMIT; COMMIT;

View File

@ -1,18 +1,18 @@
begin; begin;
attach database 'baseball-raw.db' as 'raw'; attach database 'baseball-raw.db' as 'raw';
create table if not exists teamcodes ( create table if not exists teams (
"ID" text, "ID" text,
"franchise" text "franchise" text
); );
insert into teamcodes insert into teams
select distinct teamid, franchid from "raw"."teams"; select distinct teamid, franchid from "raw"."teams";
update teamcodes update teams
set ID = 'WS9' set ID = 'WS9'
where ID = 'WAS' and franchise = 'WAS'; where ID = 'WAS' and franchise = 'WAS';
update teamcodes update teams
set ID = 'PHP' set ID = 'PHP'
where ID = 'PH4' and franchise = 'PHQ'; where ID = 'PH4' and franchise = 'PHQ';
commit; commit;