-- Create messages table
CREATE TABLE IF NOT EXISTS messages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    chat_id INTEGER NOT NULL,
    message TEXT NOT NULL,
    is_user BOOLEAN DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    response_time FLOAT,
    tokens INTEGER,
    FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
);

-- Create index on chat_id for better performance
CREATE INDEX IF NOT EXISTS idx_messages_chat_id ON messages(chat_id);

-- Create index on created_at for better sorting performance
CREATE INDEX IF NOT EXISTS idx_messages_created_at ON messages(created_at); 