ALTER TABLE tb_package_usage
    ADD COLUMN real_data_usage_mb BIGINT NOT NULL DEFAULT 0,
    ADD COLUMN virtual_data_usage_mb BIGINT NOT NULL DEFAULT 0;

COMMENT ON COLUMN tb_package_usage.real_data_usage_mb IS '历史遗留字段：真流量使用(MB)';
COMMENT ON COLUMN tb_package_usage.virtual_data_usage_mb IS '历史遗留字段：虚流量使用(MB)';

UPDATE tb_package_usage
SET
    real_data_usage_mb = data_usage_mb,
    virtual_data_usage_mb = CASE
        WHEN enable_virtual_data_snapshot = TRUE AND virtual_total_mb_snapshot > 0
            THEN LEAST(ROUND(data_usage_mb * display_gain_ratio_snapshot), data_limit_mb)::BIGINT
        ELSE data_usage_mb
    END;
