
CREATE TABLE `was_openai_request` (
	`openai_request_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
	`request_body` text DEFAULT NULL,
  `response_http_code` int(3) unsigned DEFAULT NULL,
  `response_body` text DEFAULT NULL,
  `response_timems` int(11) unsigned DEFAULT NULL,
  `tokens_prompt` int(11) unsigned DEFAULT NULL,
  `tokens_completion` int(11)unsigned  DEFAULT NULL,
  `tokens_total` int(11) unsigned DEFAULT NULL,
	`update_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
	`insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
	PRIMARY KEY (`openai_request_id`),
  KEY `idx_user_id` (`user_id`)) ENGINE = InnoDB;

CREATE TRIGGER `was_openai_request_insert_timestamp` BEFORE INSERT ON `was_openai_request` FOR EACH ROW SET NEW.insert_timestamp = NOW();

ALTER TABLE `was_openai_niche_result`
ADD COLUMN `openai_request_id` int(11) DEFAULT NULL AFTER `openai_niche_result_id`;