The teachers, janitors, baristas, etc will move to the location that gives them a better quality of life. If they decide that's not San Francisco, they can move to a better city. If SF wants them back, SF can sweeten the deal for them.
I guess it's kinda sad that not everyone who wants to live in SF gets to, but I'm not sure how "closing the door" is any more fair.
Which (as I understand it) is kind of the topic of this whole sub-discussion: it is not easy to find a solution which will sweeten the deal for them (aka: make it economically feasible and attractive for low/middle income people to live and work in a city with a housing shortage and high housing costs). Rent control is one such proposed solution. It has its benefits and drawbacks, of course, as evidenced by all the debate about it here.
Then you either pay very high rates for basic labor or you push the government to build cheaper housing. It all fixes it self.
All cities need janitors, teachers, baristas, grocery clerks, garbage collectors, etc. in order to function, and those people have to live somewhere at least within a reasonable commuting distance to the city. You can't have all the garbage collectors move out to Bakersfield and have San Francisco _just_ be a citadel of software engineers, unless the software engineers haul their own garbage, or the garbage collectors in SF also get paid $100k+ per year.