CREATE TABLE IF NOT EXISTS messages
  ( channel TEXT
  , nick TEXT NOT NULL
  , event TEXT NOT NULL
  , message TEXT
  , tags TEXT DEFAULT '{}'
  , ts GENERATED ALWAYS AS (json_extract(tags, '$.time'))
  );

CREATE INDEX IF NOT EXISTS messages_channel_nick ON messages(channel, nick);
CREATE INDEX IF NOT EXISTS messages_channel ON messages(channel);
CREATE INDEX IF NOT EXISTS messages_ts ON messages(ts);
