-- 重构: 将卡/设备的套餐系列绑定从分配ID改为系列ID
-- 重命名 tb_iot_card.series_allocation_id 为 series_id
ALTER TABLE tb_iot_card RENAME COLUMN series_allocation_id TO series_id;
COMMENT ON COLUMN tb_iot_card.series_id IS '套餐系列ID(关联PackageSeries)';

-- 重命名 tb_device.series_allocation_id 为 series_id
ALTER TABLE tb_device RENAME COLUMN series_allocation_id TO series_id;
COMMENT ON COLUMN tb_device.series_id IS '套餐系列ID(关联PackageSeries)';

-- 验证并添加复合索引（如果不存在）
CREATE INDEX IF NOT EXISTS idx_shop_series_allocation_shop_series 
    ON tb_shop_series_allocation(shop_id, series_id) 
    WHERE status = 1;
