Fix/undo migrations

This fixes undoing/rolling back migrations functionality which is reported broken in issues #707, #422 & #897.