Many more related fixes, now validated by real migration process, in a new PR
https://github.com/discourse/discourse/pull/10093