DO $$
BEGIN
    IF EXISTS (
        SELECT 1
          FROM tb_outbox_event
         WHERE event_type = 'wallet.agent_main.debited'
    ) THEN
        RAISE EXCEPTION '已存在代理主钱包统一扣款事实，禁止移除订单防重约束';
    END IF;
END
$$;

DROP INDEX IF EXISTS uq_agent_wallet_order_debit;
DROP INDEX IF EXISTS idx_order_idempotency_key;

ALTER TABLE tb_order
    DROP COLUMN IF EXISTS idempotency_key;
