Use the new batchQuery method in ExtractedImage. Also move all upgrade logic to the model.