Modified query for migration