<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run(self, migration_name, direction):
 """ Asserts an engine is configured and runs the registered migration in the given direction :param migration_name: key to a registered class in the `migration_registry` :param direction: Can be on of two values, UP or DOWN """

        if not self.engine:
            raise AttributeError("No engine configured for MigrationManager")

        connection = self.engine.connect()
        trans = connection.begin()
        try:
            migration = migration_registry[migration_name]()
            if migration.preflight():
                trans = connection.begin()

            if direction == Direction.UP:
                migration.up(connection)
            elif direction == Direction.DOWN:
                migration.down(connection)
            else:
                raise UnknowDirectionError

            if migration.check():
                trans.commit()
            else:
                raise MigrationError("Migration failed consistency checks")
        except Exception, e:
            trans.rollback()
            #XXX:dc: do more to introspect why we failed
            raise e