-- 回滚重构套餐分配和佣金系统的迁移

-- ============================================================
-- 6. 删除额外索引
-- ============================================================

DROP INDEX IF EXISTS idx_package_allocation_shop_pkg;

-- ============================================================
-- 5. 删除 tb_shop_series_commission_stats 表
-- ============================================================

DROP TABLE IF EXISTS tb_shop_series_commission_stats;

-- ============================================================
-- 4. 删除 tb_shop_package_allocation_price_history 表
-- ============================================================

DROP TABLE IF EXISTS tb_shop_package_allocation_price_history;

-- ============================================================
-- 3. 删除 tb_shop_series_allocation_config 表
-- ============================================================

DROP TABLE IF EXISTS tb_shop_series_allocation_config;

-- ============================================================
-- 2. 回滚 tb_shop_series_commission_tier 表修改
-- ============================================================

-- 回滚字段重命名
ALTER TABLE tb_shop_series_commission_tier 
RENAME COLUMN commission_value TO commission_amount;

-- 删除新增字段
ALTER TABLE tb_shop_series_commission_tier 
DROP COLUMN IF EXISTS commission_mode;

-- ============================================================
-- 1. 回滚 tb_shop_series_allocation 表修改
-- ============================================================

-- 删除新增字段
ALTER TABLE tb_shop_series_allocation 
DROP COLUMN IF EXISTS base_commission_mode,
DROP COLUMN IF EXISTS base_commission_value,
DROP COLUMN IF EXISTS enable_tier_commission;

-- 恢复旧字段
ALTER TABLE tb_shop_series_allocation 
ADD COLUMN pricing_mode VARCHAR(20),
ADD COLUMN pricing_value BIGINT,
ADD COLUMN one_time_commission_trigger VARCHAR(30),
ADD COLUMN one_time_commission_threshold BIGINT DEFAULT 0,
ADD COLUMN one_time_commission_amount BIGINT DEFAULT 0;

-- 恢复字段注释
COMMENT ON COLUMN tb_shop_series_allocation.pricing_mode IS '加价模式 fixed-固定金额 percent-百分比';
COMMENT ON COLUMN tb_shop_series_allocation.pricing_value IS '加价值（分或千分比）';
COMMENT ON COLUMN tb_shop_series_allocation.one_time_commission_trigger IS '一次性佣金触发类型 one_time_recharge-单次充值 accumulated_recharge-累计充值';
COMMENT ON COLUMN tb_shop_series_allocation.one_time_commission_threshold IS '一次性佣金触发阈值（分）';
COMMENT ON COLUMN tb_shop_series_allocation.one_time_commission_amount IS '一次性佣金金额（分）';
