Add -m migrations flag and refactoring