
CREATE TABLE `was_openai_rnd_author` (
	`openai_rnd_author_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
	`author_name` varchar(64) NOT NULL,
	`author_prompt` text NOT 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_rnd_author_id`)) ENGINE = InnoDB;

CREATE TABLE `was_openai_rnd_prompt` (
	`openai_rnd_prompt_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `prompt_slug` varchar(64) NOT NULL,
	`prompt_role` enum ('system', 'assistant', 'user') NOT NULL,
	`prompt_content` text NOT NULL,
	`prompt_variables` text 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_rnd_prompt_id`),
  UNIQUE KEY `unq_prompt_slug` (`prompt_slug`)) ENGINE = InnoDB;

CREATE TABLE `was_openai_rnd_article` (
	`openai_rnd_article_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `openai_article_id` int(11) unsigned NOT 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_rnd_article_id`),
  KEY `idx_openai_article_id` (`openai_article_id`)) ENGINE = InnoDB;

CREATE TRIGGER `was_openai_rnd_author_insert_timestamp` BEFORE INSERT ON `was_openai_rnd_author` FOR EACH ROW SET NEW.insert_timestamp = NOW();
CREATE TRIGGER `was_openai_rnd_prompt_insert_timestamp` BEFORE INSERT ON `was_openai_rnd_prompt` FOR EACH ROW SET NEW.insert_timestamp = NOW();
CREATE TRIGGER `was_openai_rnd_article_insert_timestamp` BEFORE INSERT ON `was_openai_rnd_article` FOR EACH ROW SET NEW.insert_timestamp = NOW();