CREATE TABLE IF NOT EXISTS messages (
  id TEXT PRIMARY KEY,
  to_email TEXT NOT NULL,
  from_email TEXT NOT NULL DEFAULT '',
  subject TEXT NOT NULL DEFAULT '',
  body TEXT NOT NULL DEFAULT '',
  verification_code TEXT NOT NULL DEFAULT '',
  received_at INTEGER NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_messages_to_received
  ON messages(to_email, received_at DESC);
