CREATE TABLE IF NOT EXISTS echo_publication_queue (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  echo_draft_id BIGINT UNSIGNED NULL,
  message_text MEDIUMTEXT NOT NULL,
  image_path VARCHAR(500) NULL,
  image_original_name VARCHAR(255) NULL,
  target_slug VARCHAR(40) NOT NULL DEFAULT 'echo_facebook_page',
  status ENUM('prepared','published','failed','cancelled') NOT NULL DEFAULT 'prepared',
  remote_post_id VARCHAR(160) NULL,
  remote_url VARCHAR(700) NULL,
  error_message VARCHAR(700) NULL,
  reviewed_at DATETIME NULL,
  published_at DATETIME NULL,
  created_at DATETIME NOT NULL,
  updated_at DATETIME NOT NULL,
  FOREIGN KEY(echo_draft_id) REFERENCES echo_drafts(id) ON DELETE SET NULL,
  INDEX echo_publication_status(status,created_at),
  INDEX echo_publication_target(target_slug,published_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
