CREATE TABLE messages (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    session_id INTEGER NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
    user BOOLEAN NOT NULL CHECK (user IN (0, 1)),
    reasoning TEXT,
    reasoning_complete BOOLEAN NOT NULL DEFAULT 1 CHECK (reasoning_complete IN (0, 1)),
    content TEXT NOT NULL
);

CREATE INDEX messages_session_id ON messages(session_id);
