-- 新增支付宝配置字段到 tb_wechat_config
ALTER TABLE tb_wechat_config
    ADD COLUMN IF NOT EXISTS ali_app_id             varchar(100) NOT NULL DEFAULT '',
    ADD COLUMN IF NOT EXISTS ali_private_key        text         NOT NULL DEFAULT '',
    ADD COLUMN IF NOT EXISTS ali_public_key         text         NOT NULL DEFAULT '',
    ADD COLUMN IF NOT EXISTS ali_notify_url         varchar(500) NOT NULL DEFAULT '',
    ADD COLUMN IF NOT EXISTS ali_return_url         varchar(500) NOT NULL DEFAULT '',
    ADD COLUMN IF NOT EXISTS ali_production         boolean      NOT NULL DEFAULT false,
    ADD COLUMN IF NOT EXISTS ali_pay_expire_minutes integer      NOT NULL DEFAULT 30;

-- 新增支付单过期时间字段
ALTER TABLE tb_payment
    ADD COLUMN IF NOT EXISTS expire_at timestamptz;

-- 新增索引：按业务单+支付方式+状态查询
CREATE INDEX IF NOT EXISTS idx_tb_payment_order_method_status
    ON tb_payment (order_id, order_type, payment_method, status, created_at DESC);
