
CREATE TABLE `was_openai_bulk_article` (
  `openai_bulk_article_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `openai_author_id` int(11) unsigned DEFAULT NULL,
  `user_id` int(11) unsigned NOT NULL,
  `sections_count` 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_bulk_article_id`),
  KEY `idx_openai_author_id` (`openai_author_id`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB COMMENT='stores bulk articles';

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


CREATE TABLE `was_openai_bulk_article_blog` (
  `openai_bulk_article_blog_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `openai_bulk_article_id` int(11) unsigned NOT NULL,
  `openai_article_id` int(11) unsigned DEFAULT NULL,
  `blog_topic` varchar(256) NOT NULL,
  `blog_summary` 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_bulk_article_blog_id`),
  KEY `idx_openai_bulk_article_id` (`openai_bulk_article_id`),
  KEY `idx_openai_article_id` (`openai_article_id`)
) ENGINE=InnoDB COMMENT='stores bulk articles of type blog';

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

INSERT INTO `was_openai_wordcount_event` (`event_slug`, `event_description`)
VALUES ('bulk-articles', 'Bulk articles generated');
