-- =============================================================================
--  ai_conversation
--
--  A persistent chat conversation. Lets you build apps where the user's
--  chat history with the AI module survives page reloads / sessions.
--  Optional — Chat plugin is happy in-memory if you don't need persistence.
-- =============================================================================

CREATE TABLE IF NOT EXISTS ai_conversation (
    ai_conversation_id         INT(11)      NOT NULL AUTO_INCREMENT,
    ai_conversation_user_id    INT(11)      NULL,        -- FK user.user_id, nullable for anonymous
    ai_conversation_title      VARCHAR(255) NULL,
    ai_conversation_model      VARCHAR(128) NOT NULL,
    ai_conversation_created_at TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ai_conversation_updated_at TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (ai_conversation_id),
    KEY ai_conversation_user_idx (ai_conversation_user_id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
