Restore upgrade-to-engine code.

This partially reverts commit b1b1520f3e5b32e06d8042032675cef6620118bf.