-- IotCard 表添加 carrier_type、carrier_name 冗余字段
-- 导入时从 Carrier 表快照，后续查询无需 JOIN

ALTER TABLE tb_iot_card ADD COLUMN carrier_type VARCHAR(20);
ALTER TABLE tb_iot_card ADD COLUMN carrier_name VARCHAR(100);

COMMENT ON COLUMN tb_iot_card.carrier_type IS '运营商类型(CMCC/CUCC/CTCC/CBN)，导入时快照';
COMMENT ON COLUMN tb_iot_card.carrier_name IS '运营商名称，导入时快照';

-- 从 Carrier 表填充现有数据
UPDATE tb_iot_card 
SET carrier_type = c.carrier_type, carrier_name = c.carrier_name
FROM tb_carrier c 
WHERE tb_iot_card.carrier_id = c.id;
