migrations: Refactor desguar operations
Created by: efritz
Pulled from #29831. This PR improves the error conditions in desugaring operations. In particular, we check the length before referencing the leaf versions slice within the desguarRevert
function. This change also makes the remaining behavioral diff of #29831 in this file trivially understandable.