CREATE TABLE IF NOT EXISTS `{{prefix}}email_queue_runs` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `trigger_type` VARCHAR(40) NOT NULL,
  `status` ENUM('success','warning','failed','busy') NOT NULL DEFAULT 'success',
  `selected_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `sent_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `retry_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `failed_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `skipped_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `recovered_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `message` TEXT NULL,
  `started_by` BIGINT UNSIGNED NULL,
  `started_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `completed_at` DATETIME NULL,
  PRIMARY KEY (`id`),
  KEY `idx_email_queue_run_time` (`started_at`),
  KEY `idx_email_queue_run_status` (`status`,`started_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
