public function rollback(CapsuleInterface $capsule = null): ?MigrationInterface
    {
        if (!$this->isConfigured()) {
            throw new MigrationException("Unable to run migration, Migrator not configured");
        }

        /** @var MigrationInterface $migration */
        foreach (array_reverse($this->getMigrations()) as $migration) {
            if ($migration->getState()->getStatus() != State::STATUS_EXECUTED) {
                continue;
            }

            $capsule = $capsule ?? new Capsule($this->dbal->database($migration->getDatabase()));
            $capsule->getDatabase()->transaction(function () use ($migration, $capsule) {
                $migration->withCapsule($capsule)->down();
            });

            $this->migrationTable($migration->getDatabase())->delete([
                'migration' => $migration->getState()->getName()
            ])->run();

            return $migration->withState($this->resolveState($migration));
        }

        return null;
    }