Fix detached head situation while running migrations