Risk-driven migration and the collective-risk social dilemma