-- 新增设备虚拟号快照列
ALTER TABLE tb_iot_card
    ADD COLUMN IF NOT EXISTS device_virtual_no VARCHAR(100) NOT NULL DEFAULT '';

-- 回填现有已绑定卡的设备虚拟号
UPDATE tb_iot_card c
SET device_virtual_no = d.virtual_no
FROM tb_device_sim_binding b
JOIN tb_device d ON d.id = b.device_id
WHERE b.iot_card_id = c.id
  AND b.bind_status = 1
  AND b.deleted_at IS NULL
  AND d.deleted_at IS NULL;
