CREATE TABLE IF NOT EXISTS `ai_session` (
  `session_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `uuid` VARCHAR(64) NOT NULL,
  `site_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `admin_id` INT UNSIGNED NOT NULL DEFAULT 0,
  `title` VARCHAR(255) NOT NULL DEFAULT '',
  `messages` MEDIUMTEXT NOT NULL,
  `message_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`session_id`),
  UNIQUE KEY `uuid_admin_site` (`uuid`,`site_id`,`admin_id`),
  KEY `admin_site_updated` (`site_id`,`admin_id`,`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
