Reimplements migration which was broken by move to container2, also fixes some other broke migration code [#893 state:resolved]