Latvia had broken away from the Soviet Union after the Russian Revolution, (having briefly been a 'Latvian SSR') and remained independent until the Molotov-Ribbentrop Pact. It was annexed by the Soviet Union in 1940, and then occupied by Nazi Germany the year after. The Latvian SSR was restored after liberation by the Soviet Union.
The Latvian SSR, along with the other Baltic Republics was allowed greater autonomy in the late 1980s, and in 1988 the old pre-war Flag of Latvia was allowed to be used, and replaced the Soviet Latvian flag as the official flag in 1990. The Latvian SSR became the independent state of Latvia on August 21, 1991.