SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Host 政策是小型配置表；迁移仅追加定长列并使用在线 DDL，不扫描钱包、提现或用户流水。
-- 新渠道字段以 0 表示尚未拆分，运行时回退旧 minimum_withdraw_usd_minor，因此无需全表 UPDATE 回填。
SET @ddl = IF((SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_host_agency_salary_policies' AND COLUMN_NAME = 'coin_seller_minimum_withdraw_usd_minor') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN coin_seller_minimum_withdraw_usd_minor BIGINT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 用户找币商最低提现美元美分；0 回退旧字段'' AFTER minimum_withdraw_usd_minor, ALGORITHM=INPLACE, LOCK=NONE', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @ddl = IF((SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_host_agency_salary_policies' AND COLUMN_NAME = 'platform_minimum_withdraw_usd_minor') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN platform_minimum_withdraw_usd_minor BIGINT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 用户找平台最低提现美元美分；0 回退旧字段'' AFTER coin_seller_minimum_withdraw_usd_minor, ALGORITHM=INPLACE, LOCK=NONE', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @ddl = IF((SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_host_agency_salary_policies' AND COLUMN_NAME = 'diamond_exchange_enabled') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN diamond_exchange_enabled BOOLEAN NOT NULL DEFAULT TRUE COMMENT ''是否开放 POINT_DIAMOND 兑换金币'' AFTER platform_minimum_withdraw_usd_minor, ALGORITHM=INPLACE, LOCK=NONE', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;
