Fixed #22474 -- Made migration recorder aware of multiple databases

Thanks Tim Graham for the review.