refactor postgres migration