CREATE TABLE IF NOT EXISTS llm_conversations (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    started_at      INTEGER NOT NULL,
    last_message_at INTEGER NOT NULL,
    title           TEXT,
    pinned          INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX IF NOT EXISTS idx_llm_conversations_pinned ON llm_conversations(pinned DESC, last_message_at DESC);

CREATE TABLE IF NOT EXISTS llm_messages (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    conversation_id INTEGER NOT NULL REFERENCES llm_conversations(id),
    role            TEXT NOT NULL,           -- "user" | "assistant" | "tool" | "system"
    content         TEXT NOT NULL,
    tool_calls_json TEXT,
    timestamp       INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_llm_messages_conversation
    ON llm_messages(conversation_id, timestamp);
