-- 回滚迁移: 一次性佣金功能

-- ========================================
-- 1. 恢复 tb_commission_record 表结构
-- ========================================

-- 1.1 删除新字段
ALTER TABLE tb_commission_record
    DROP COLUMN IF EXISTS commission_source,
    DROP COLUMN IF EXISTS iot_card_id,
    DROP COLUMN IF EXISTS device_id,
    DROP COLUMN IF EXISTS remark;

-- 1.2 恢复旧字段
ALTER TABLE tb_commission_record
    ADD COLUMN IF NOT EXISTS agent_id BIGINT,
    ADD COLUMN IF NOT EXISTS rule_id BIGINT,
    ADD COLUMN IF NOT EXISTS commission_type VARCHAR(50),
    ADD COLUMN IF NOT EXISTS unfrozen_at TIMESTAMP WITH TIME ZONE;

-- 1.3 恢复索引
CREATE INDEX IF NOT EXISTS idx_commission_record_agent_id ON tb_commission_record(agent_id);
CREATE INDEX IF NOT EXISTS idx_commission_record_rule_id ON tb_commission_record(rule_id);

-- ========================================
-- 2. 删除 tb_shop_series_one_time_commission_tier 表
-- ========================================

DROP TABLE IF EXISTS tb_shop_series_one_time_commission_tier;

-- ========================================
-- 3. 删除 tb_shop_series_allocation 的一次性佣金字段
-- ========================================

ALTER TABLE tb_shop_series_allocation
    DROP COLUMN IF EXISTS enable_one_time_commission,
    DROP COLUMN IF EXISTS one_time_commission_type,
    DROP COLUMN IF EXISTS one_time_commission_trigger,
    DROP COLUMN IF EXISTS one_time_commission_threshold,
    DROP COLUMN IF EXISTS one_time_commission_mode,
    DROP COLUMN IF EXISTS one_time_commission_value;
