Add tests for the migrate command and fix a bug they exposed