Bring over upgrade logic and implement a generic batchQuery method.