Both were part of Poland for something on the order of 500 years , including at least a few decades of the 20th century , before the Nazis invaded and then Stalin moved the territory of Ukraine to the west , and Lviv became just another battered and tragic city in the Soviet Union .