WIP: Backport migration fixes from #6650

:construction: WIP
(backports to stable6, despite branch name)