CREATE TABLE IF NOT EXISTS `wpjy_openai_logs` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `feature` VARCHAR(80) NOT NULL,
  `target_type` VARCHAR(80) DEFAULT NULL,
  `target_id` BIGINT DEFAULT NULL,
  `model` VARCHAR(80) DEFAULT NULL,
  `response_id` VARCHAR(120) DEFAULT NULL,
  `status` VARCHAR(20) NOT NULL DEFAULT 'ok',
  `prompt_hash` CHAR(64) DEFAULT NULL,
  `prompt_preview` TEXT DEFAULT NULL,
  `output_preview` MEDIUMTEXT DEFAULT NULL,
  `error_message` TEXT DEFAULT NULL,
  `meta_json` LONGTEXT DEFAULT NULL,
  `created_by` BIGINT DEFAULT NULL,
  `created_at` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_feature_created` (`feature`, `created_at`),
  KEY `idx_target` (`target_type`, `target_id`),
  KEY `idx_status_created` (`status`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
