CREATE TABLE IF NOT EXISTS `{{prefix}}queue_status_history` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `queue_entry_id` BIGINT UNSIGNED NOT NULL,
  `previous_status` VARCHAR(40) NULL,
  `new_status` VARCHAR(40) NOT NULL,
  `notes` VARCHAR(255) NULL,
  `changed_by` BIGINT UNSIGNED NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_queue_history_entry` (`queue_entry_id`,`created_at`),
  CONSTRAINT `{{prefix}}fk_queue_history_entry` FOREIGN KEY (`queue_entry_id`) REFERENCES `{{prefix}}queue_entries` (`id`) ON DELETE CASCADE,
  CONSTRAINT `{{prefix}}fk_queue_history_user` FOREIGN KEY (`changed_by`) REFERENCES `{{prefix}}users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
