In 1821, Mexico won its independence from Spain, and San Diego became part of the Mexican territory of Alta California