mlblive-mastodon-scripts/schema.sql

35 lines
805 B
SQL

create table if not exists plays (
"json" text unique on conflict ignore,
"posted" integer check ("posted" in (0, 1))
);
create index if not exists nonposted_plays
on plays(posted)
where posted = 0;
create table if not exists highlights (
"json" text unique on conflict ignore,
"posted" integer check ("posted" in (0, 1))
);
create index if not exists nonposted_highlights
on highlights(posted)
where posted = 0;
create table if not exists games (
gamePk integer,
teamId text,
json text,
posted integer,
unique (teamId, gamePk) on conflict ignore
);
create trigger if not exists delete_old_states
before insert on games
begin
delete from games
where gamePk = new.gamePk and
teamId = new.teamId and
json ->> 'status' ->> 'detailedState' != new.json ->> 'status' ->> 'detailedState';
end;