SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

-- 仅扩展小型政策配置表；每列先查 information_schema，使迁移可安全重放且不扫描钱包流水。
SET @ddl = IF((SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_host_agency_salary_policies' AND COLUMN_NAME = 'policy_type') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN policy_type VARCHAR(32) NOT NULL DEFAULT ''SALARY_DIAMOND'' COMMENT ''政策类型：SALARY_DIAMOND/POINT_DIAMOND'' AFTER name, 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 = 'point_diamonds_per_usd') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN point_diamonds_per_usd BIGINT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 每美元对应钻石积分'' AFTER gift_coin_to_diamond_ratio, 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 = 'coins_per_usd') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN coins_per_usd BIGINT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 每美元对应金币'' AFTER point_diamonds_per_usd, 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 = 'minimum_withdraw_usd_minor') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN minimum_withdraw_usd_minor BIGINT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 最低提现美元美分'' AFTER coins_per_usd, 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 = 'withdraw_fee_bps') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN withdraw_fee_bps INT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 提现费率基点'' 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 = 'agency_point_share_bps') = 0,
  'ALTER TABLE admin_host_agency_salary_policies ADD COLUMN agency_point_share_bps INT NOT NULL DEFAULT 0 COMMENT ''POINT_DIAMOND 代理分成占主播基础积分的基点'' AFTER withdraw_fee_bps, ALGORITHM=INPLACE, LOCK=NONE', 'SELECT 1');
PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt;

