-- Competitor comparisons.
-- Competitor comparison per website (homepage table + /compare page).
CREATE TABLE IF NOT EXISTS comparisons (
  website_id    INT PRIMARY KEY,
  published     JSON,                                -- live comparison
  draft         JSON,                                -- awaiting approval (research or re-check)
  draft_kind    ENUM('research','recheck') NULL,
  changes       JSON,                                -- what a re-check changed
  link_report   JSON,                                -- HTTP status of competitor links
  show_on_home  TINYINT(1) NOT NULL DEFAULT 1,
  checked_at    DATETIME,
  published_at  DATETIME,
  draft_at      DATETIME,
  updated_at    DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  CONSTRAINT fk_cmp_site FOREIGN KEY (website_id) REFERENCES websites(id) ON DELETE CASCADE
) ENGINE=InnoDB CHARSET=utf8mb4;

ALTER TABLE batches
  MODIFY type ENUM('research_market','generate_guide','generate_content','generate_brief','build_deliverable','compare_research','compare_recheck') NOT NULL;
