[
  {
    "type": "alter_table",
    "description": "Add Intercom sync columns to support_articles for one-way push to Intercom Help Center",
    "database": "kiosk_buykiosk",
    "check_query": "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'support_articles' AND COLUMN_NAME = 'intercom_article_id'",
    "sql": "ALTER TABLE `support_articles` ADD COLUMN `intercom_article_id` varchar(64) DEFAULT NULL COMMENT 'Intercom Help Center article id (set after first sync)' AFTER `published_at`, ADD COLUMN `intercom_synced_at` timestamp NULL DEFAULT NULL COMMENT 'When this article was last successfully pushed to Intercom' AFTER `intercom_article_id`, ADD COLUMN `intercom_sync_error` text DEFAULT NULL COMMENT 'Last sync error message (NULL = healthy)' AFTER `intercom_synced_at`, ADD COLUMN `intercom_sync_hash` char(64) DEFAULT NULL COMMENT 'sha256(title|html|status|category) — skip API calls when unchanged' AFTER `intercom_sync_error`, ADD KEY `idx_intercom_article_id` (`intercom_article_id`), ADD KEY `idx_intercom_synced_at` (`intercom_synced_at`)"
  },
  {
    "type": "create_table",
    "description": "Mapping from local support_categories to Intercom Help Center collections",
    "database": "kiosk_buykiosk",
    "check_query": "SHOW TABLES LIKE 'support_intercom_collections'",
    "sql": "CREATE TABLE `support_intercom_collections` (\n  `category_id` int(10) unsigned NOT NULL COMMENT 'FK to support_categories.id',\n  `intercom_collection_id` varchar(64) NOT NULL COMMENT 'Intercom collection id',\n  `intercom_parent_id` varchar(64) DEFAULT NULL COMMENT 'Parent collection id (mirrors local parent_id)',\n  `synced_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n  PRIMARY KEY (`category_id`),\n  UNIQUE KEY `uk_intercom_collection_id` (`intercom_collection_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Mapping from local support categories to Intercom Help Center collections'"
  }
]
