SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;
SET time_zone = '+00:00';

USE hyapp_wallet;

-- 配置表按 (app_code, seller_user_id) 唯一且行数很小；MySQL 8 的 INSTANT 加 nullable JSON 列不复制表、
-- 不扫描账务流水，也不回填历史行。旧行 NULL 与新写入 [] 都表示未限制区域，并继续读取既有国家白名单。
SET @ddl := IF(
  (SELECT COUNT(*) FROM information_schema.COLUMNS
   WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'point_withdrawal_coin_seller_configs' AND COLUMN_NAME = 'service_region_ids') = 0,
  'ALTER TABLE point_withdrawal_coin_seller_configs ADD COLUMN service_region_ids JSON NULL COMMENT ''服务区域 ID 数组；与国家数组互斥，两个数组都为空表示全量'' AFTER service_country_codes, ALGORITHM=INSTANT',
  'SELECT 1'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
