-- 回滚永久积分结构；旧到期日期已无法恢复，现有批次统一设为无限期。
DROP INDEX IF EXISTS public.idx_point_grants_user_available;

ALTER TABLE public.point_grants
    ADD COLUMN expires_at timestamp with time zone NOT NULL DEFAULT 'infinity'::timestamptz;

ALTER TABLE public.point_grants
    ALTER COLUMN expires_at DROP DEFAULT;

CREATE INDEX idx_point_grants_user_expiry
    ON public.point_grants(user_id, expires_at, created_at, id)
    WHERE available_amount > 0;

COMMENT ON INDEX public.idx_point_grants_user_expiry IS '加速按用户和到期时间锁定可用积分批次';
