def handle(self, *args, **kwargs): session = MigrationSession(None, kwargs['database']) unapplied, current = session.list_migrations() # Compose the output YAML. yaml_output = yaml.safe_dump({ 'migrations': [{ 'app': item[0], 'migration': item[1] } for item in unapplied], 'initial_states': [{ 'app': item[0], 'migration': item[1] } for item in current], 'database': kwargs['database'] }) # Output the composed YAML. self.stdout.write(yaml_output) if kwargs['output_file']: with open(kwargs['output_file'], 'w') as outfile: outfile.write(yaml_output) if kwargs['fail_on_unapplied'] and unapplied: sys.exit(1) else: sys.exit(0)
def handle(self, *args, **kwargs): migrator = MigrationSession(self.stderr, kwargs['database']) failure = False try: migrator.apply_all() except CommandError as e: self.stderr.write("Migration error: {}".format(e)) failure = True state = dump_migration_session_state(migrator.state) self.stdout.write(state) if kwargs['output_file']: with open(kwargs['output_file'], 'w') as outfile: outfile.write(state) sys.exit(int(failure))
def test_migration_regex(self, status_string, is_match, success): migrator = MigrationSession(sys.stderr, 'default') match = migrator.migration_regex.match(status_string) self.assertEqual(is_match, match is not None) if match: self.assertEqual(success, match.group('success') == 'OK')