CREATE TABLE IF NOT EXISTS messages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    chat_id INTEGER NOT NULL,
    timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
    text TEXT NOT NULL,
    is_user BOOL NOT NULL,

    UNIQUE(id, chat_id)
);

CREATE INDEX idx_message_timestamp ON messages(timestamp);
CREATE INDEX idx_message_chat_id ON messages(chat_id);
