-- 回滚：恢复 tb_iot_card 和 tb_device 表中的 owner_type 和 owner_id 字段

-- 恢复 tb_iot_card.iccid 字段长度
ALTER TABLE tb_iot_card ALTER COLUMN iccid TYPE varchar(50);
COMMENT ON COLUMN tb_iot_card.iccid IS 'ICCID(唯一标识)';

-- 恢复 tb_iot_card 的 owner_type 和 owner_id 列
ALTER TABLE tb_iot_card ADD COLUMN IF NOT EXISTS owner_type varchar(20) NOT NULL DEFAULT 'platform';
ALTER TABLE tb_iot_card ADD COLUMN IF NOT EXISTS owner_id bigint NOT NULL DEFAULT 0;
COMMENT ON COLUMN tb_iot_card.owner_type IS '所有者类型 platform-平台 shop-店铺';
COMMENT ON COLUMN tb_iot_card.owner_id IS '所有者ID';
CREATE INDEX IF NOT EXISTS idx_iot_card_owner_id ON tb_iot_card(owner_id);

-- 恢复 tb_device 的 owner_type 和 owner_id 列
ALTER TABLE tb_device ADD COLUMN IF NOT EXISTS owner_type varchar(20) NOT NULL DEFAULT 'platform';
ALTER TABLE tb_device ADD COLUMN IF NOT EXISTS owner_id bigint NOT NULL DEFAULT 0;
COMMENT ON COLUMN tb_device.owner_type IS '所有者类型 platform-平台 shop-店铺';
COMMENT ON COLUMN tb_device.owner_id IS '所有者ID';
CREATE INDEX IF NOT EXISTS idx_device_owner_id ON tb_device(owner_id);

-- 恢复 shop_id 字段的注释
COMMENT ON COLUMN tb_iot_card.shop_id IS '店铺ID（冗余字段，方便查询）';
COMMENT ON COLUMN tb_device.shop_id IS '店铺ID（冗余字段，方便查询）';
