public function migrate($to = null)
    {
        if (null === $to) {
            $to = $this->configuration->getLatestVersion();
        }

        $from = $this->configuration->getCurrentVersion();
        $from = (string) $from;
        $to = (string) $to;

        $migrations = $this->configuration->getMigrations();
        if (!isset($migrations[$to]) && $to > 0) {
            throw new UnknownVersionException($to);
        }

        $direction = $from > $to ? 'down' : 'up';
        $migrationsToExecute = $this->configuration->getMigrationsToExecute($direction, $to);

        if ($from === $to && empty($migrationsToExecute) && $migrations) {
            return;
        }

        $this->outputWriter->write(sprintf('Migrating <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>', $direction, $to, $from));

        if (empty($migrationsToExecute)) {
            throw new NoMigrationsToExecuteException('Could not find any migrations to execute.');
        }

        $time = 0;
        foreach ($migrationsToExecute as $version) {
            $version->execute($direction);
            $time += $version->getTime();
        }

        $this->outputWriter->write("\n  <comment>------------------------</comment>\n");
        $this->outputWriter->write(sprintf('  <info>++</info> finished in %s', $time));
        $this->outputWriter->write(sprintf('  <info>++</info> %s migrations executed', count($migrationsToExecute)));
    }