If people in midevil times drank beer and wine to avoid contaminated water
They didn't, it's a fallacy. See these posts below. Some are bit older so if you have followup questions you can post them here, and tag a specific person if you want so they know to come a' answerin'.
Your question rests on a false premise; medieval people did not drink beer and wine to avoid contaminated water. They were quite able to understand how to source fresh water barring unusual events.
You may be interested in this section of our FAQ, on drinking water:
https://www.reddit.com/r/AskHistorians/wiki/health#wiki_drinking_water