-- 回滚: 客户端接口数据模型基础准备

-- 9. tb_personal_customer: 恢复唯一索引
DROP INDEX IF EXISTS idx_personal_customer_wx_open_id;
CREATE UNIQUE INDEX idx_personal_customer_wx_open_id ON tb_personal_customer(wx_open_id) WHERE deleted_at IS NULL;

-- 7. tb_shop_package_allocation: 移除 retail_price
ALTER TABLE tb_shop_package_allocation DROP COLUMN IF EXISTS retail_price;

-- 6. tb_carrier: 移除实名链接配置
ALTER TABLE tb_carrier DROP COLUMN IF EXISTS realname_link_template;
ALTER TABLE tb_carrier DROP COLUMN IF EXISTS realname_link_type;

-- 5. tb_asset_recharge_record: 移除新增字段
ALTER TABLE tb_asset_recharge_record DROP COLUMN IF EXISTS linked_carrier_id;
ALTER TABLE tb_asset_recharge_record DROP COLUMN IF EXISTS linked_carrier_type;
ALTER TABLE tb_asset_recharge_record DROP COLUMN IF EXISTS linked_order_type;
ALTER TABLE tb_asset_recharge_record DROP COLUMN IF EXISTS linked_package_ids;
ALTER TABLE tb_asset_recharge_record DROP COLUMN IF EXISTS generation;
ALTER TABLE tb_asset_recharge_record DROP COLUMN IF EXISTS operator_type;

-- 4. tb_package_usage: 移除 generation
ALTER TABLE tb_package_usage DROP COLUMN IF EXISTS generation;

-- 3. tb_order: 移除 source 和 generation
ALTER TABLE tb_order DROP COLUMN IF EXISTS generation;
ALTER TABLE tb_order DROP COLUMN IF EXISTS source;

-- 2. tb_device: 移除 asset_status 和 generation
ALTER TABLE tb_device DROP COLUMN IF EXISTS generation;
ALTER TABLE tb_device DROP COLUMN IF EXISTS asset_status;

-- 1. tb_iot_card: 移除 asset_status 和 generation
ALTER TABLE tb_iot_card DROP COLUMN IF EXISTS generation;
ALTER TABLE tb_iot_card DROP COLUMN IF EXISTS asset_status;
