move over parks

This commit is contained in:
Nick Griffey 2024-01-27 18:59:05 -06:00
parent f1bb5512bf
commit 7495572192
3 changed files with 26 additions and 5 deletions

View File

@ -9,13 +9,14 @@ baseball.db: baseball-transformed.db sql/load.sql
cat sql/load.sql | sqlite3 baseball.db
sqlite3 baseball.db "VACUUM"
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql
rm -f baseball-transformed.db
cp baseball-raw.db baseball-transformed.db
cat sql/franchises.sql | sqlite3 baseball-transformed.db
cat sql/franchiseseasons.sql | sqlite3 baseball-transformed.db
cat sql/awards.sql | sqlite3 baseball-transformed.db
cat sql/seasons.sql | sqlite3 baseball-transformed.db
cat sql/parks.sql | sqlite3 baseball-transformed.db
baseball-raw.db:
rm -f baseball-raw.db

View File

@ -114,4 +114,24 @@ CREATE TABLE "people" (
);
INSERT INTO "people" SELECT DISTINCT * FROM "transformed"."people";
CREATE TABLE IF NOT EXISTS "parks" (
"park.key" TEXT,
"park.name" TEXT,
"city" TEXT,
"state" TEXT,
"country" TEXT,
PRIMARY KEY("park.key")
);
insert into "parks" select distinct * from "transformed"."parks";
CREATE TABLE IF NOT EXISTS "parkaliases" (
"ID" TEXT,
"alias" TEXT,
PRIMARY KEY("ID","alias"),
foreign key("ID") references "parks"("park.key")
);
insert into "parkaliases" select distinct * from "transformed"."parkaliases";
COMMIT;

View File

@ -1,14 +1,14 @@
begin;
attach database 'baseball-raw.db' as 'raw';
create table if not exists "parkaliases" (
"parkID" text,
"alias" text,
primary key("parkID","alias"),
foreign key("parkID") references "parks"("park.key")
"alias" text
);
-- split aliases by semicolon
with recursive aliases(parkid, alias) as (
select "park.key", "park.alias" from parks
select "park.key", "park.alias" from "raw"."parks"
union
select parkid, trim(substr(alias, instr(alias, ";") + 1)) as a
from aliases