rename table

This commit is contained in:
Nick Griffey 2024-01-27 21:45:23 -06:00
parent ec2a2057f2
commit 45b6b1a79a
3 changed files with 12 additions and 12 deletions

View File

@ -9,11 +9,11 @@ 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/teams.sql baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.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
cat sql/franchiseseasons.sql | sqlite3 baseball-transformed.db cat sql/teamseasons.sql | sqlite3 baseball-transformed.db
cat sql/awards.sql | sqlite3 baseball-transformed.db cat sql/awards.sql | sqlite3 baseball-transformed.db
cat sql/seasons.sql | sqlite3 baseball-transformed.db cat sql/seasons.sql | sqlite3 baseball-transformed.db
cat sql/parks.sql | sqlite3 baseball-transformed.db cat sql/parks.sql | sqlite3 baseball-transformed.db

View File

@ -20,11 +20,10 @@ CREATE TABLE IF NOT EXISTS "franchises" (
insert into franchises insert into franchises
select distinct * from "transformed"."franchises"; select distinct * from "transformed"."franchises";
create table if not exists "franchiseseasons" ( create table if not exists "teamseasons" (
"year" NUMERIC, "year" NUMERIC,
"league" TEXT, "league" TEXT,
"team" TEXT, "team" TEXT,
"franchise" TEXT,
"division" TEXT, "division" TEXT,
"Rank" NUMERIC, "Rank" NUMERIC,
"G" NUMERIC, "G" NUMERIC,
@ -69,14 +68,13 @@ create table if not exists "franchiseseasons" (
"teamIDBR" TEXT, "teamIDBR" TEXT,
"teamIDlahman45" TEXT, "teamIDlahman45" TEXT,
"teamIDretro" TEXT, "teamIDretro" TEXT,
PRIMARY KEY("year","franchise"), PRIMARY KEY("year","team"),
foreign key("year") references "seasons"("year"), foreign key("year") references "seasons"("year"),
foreign key("team") references "teams"("ID"), foreign key("team") references "teams"("ID")
foreign key("franchise") references "franchises"("ID")
); );
insert into franchiseseasons insert into teamseasons
select distinct * from "transformed"."franchiseseasons"; select distinct * from "transformed"."teamseasons";
create table if not exists "seasons" ( create table if not exists "seasons" (
"year" numeric, "year" numeric,

View File

@ -1,11 +1,13 @@
begin; begin;
alter table "teams" rename to "franchiseseasons"; alter table "teams" rename to "teamseasons";
update franchiseseasons update teamseasons
set teamid = 'WS9' set teamid = 'WS9'
where teamid = 'WAS' and franchid = 'WAS'; where teamid = 'WAS' and franchid = 'WAS';
update franchiseseasons update teamseasons
set teamid = 'PHP' set teamid = 'PHP'
where teamid = 'PH4' and franchid = 'PHQ'; where teamid = 'PH4' and franchid = 'PHQ';
alter table "teamseasons" drop column "franchID";
commit; commit;