-- 为卡密类型添加充值类型和时长单位字段
ALTER TABLE card_types ADD COLUMN recharge_type VARCHAR(20) DEFAULT 'balance';
ALTER TABLE card_types ADD COLUMN value_unit VARCHAR(20) DEFAULT 'day';

-- 更新现有数据：根据应用的计费方式设置充值类型
UPDATE card_types 
SET recharge_type = CASE 
    WHEN application_id IN (SELECT id FROM applications WHERE billing_type = 'subscription') 
    THEN 'subscription' 
    ELSE 'balance' 
END;

-- 为订阅充值类型设置默认时长单位
UPDATE card_types 
SET value_unit = 'day' 
WHERE recharge_type = 'subscription' AND (value_unit IS NULL OR value_unit = '');
