Fix migration logic and dependencies