Refactor db migrations with constraints