drop table if exists loglines;
create table loglines (
  ser       serial,
  idx       integer not null,
  t         timestamp,
  chan      text not null,
  era       integer not null,
  speaker   text not null,
  self      boolean,
  payload   text not null,
  backlinks integer[],
  PRIMARY KEY(idx, chan),
  UNIQUE(idx, chan)
);


create index logline_idx_i     on loglines(idx);
create index logline_t_i       on loglines(t);
create index logline_chan_i    on loglines(chan);
create index logline_era_i     on loglines(era);
create index logline_speaker_i on loglines(speaker);
create index logline_payload_i on loglines(payload);

CREATE EXTENSION pg_trgm;

-- drop index payload_search_idx;

create index concurrently payload_search_idx
ON loglines USING gin (payload gin_trgm_ops);
