pragma foreign_keys = 0;

begin;
attach database 'lahman-raw.db' as 'raw';

create temp table franchises as
select * from "raw".teamsfranchises;

update franchises
set active = 'N'
where active = 'NA';

update franchises
set
	NAassoc = nullif(NAassoc,'');

CREATE TABLE IF NOT EXISTS main."franchises" (
	"ID"	TEXT,
	"name"	TEXT,
	"active"	TEXT	check ("active" in ('Y','N')),
	"NAassoc"	TEXT,
	PRIMARY KEY("ID")
);

insert into main.franchises
select distinct * from temp."franchises";
commit;
