-- Expand wallet recharge record currency codes so Google Play products such as USDT
-- can be snapshotted before payment order auditing and Google consume.

SET @wallet_recharge_record_currency_ddl := (
  SELECT CASE
    WHEN COUNT(*) = 0 THEN 'SELECT 1'
    WHEN MAX(CHARACTER_MAXIMUM_LENGTH) < 8 THEN
      'ALTER TABLE wallet_recharge_records MODIFY COLUMN currency_code VARCHAR(8) NOT NULL COMMENT ''币种编码'''
    ELSE 'SELECT 1'
  END
  FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'wallet_recharge_records'
    AND COLUMN_NAME = 'currency_code'
);

PREPARE stmt FROM @wallet_recharge_record_currency_ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SELECT
  COLUMN_TYPE AS wallet_recharge_records_currency_code_type,
  IS_NULLABLE AS wallet_recharge_records_currency_code_nullable
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'wallet_recharge_records'
  AND COLUMN_NAME = 'currency_code';
