public function generateMigration($diffAgainstCurrent = true, $filterExpression = null)
    {
        $configuration = $this->getMigrationConfiguration();
        $up = null;
        $down = null;

        if ($diffAgainstCurrent === true) {
            /** @var \Doctrine\DBAL\Connection $connection */
            $connection = $this->entityManager->getConnection();

            if ($filterExpression) {
                $connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression);
            }

            $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();

            if (empty($metadata)) {
                return ['No mapping information to process.', null];
            }

            $tool = new SchemaTool($this->entityManager);

            $fromSchema = $connection->getSchemaManager()->createSchema();
            $toSchema = $tool->getSchemaFromMetadata($metadata);

            if ($filterExpression) {
                foreach ($toSchema->getTables() as $table) {
                    $tableName = $table->getName();
                    if (!preg_match($filterExpression, $this->resolveTableName($tableName))) {
                        $toSchema->dropTable($tableName);
                    }
                }

                foreach ($toSchema->getSequences() as $sequence) {
                    $sequenceName = $sequence->getName();
                    if (!preg_match($filterExpression, $this->resolveTableName($sequenceName))) {
                        $toSchema->dropSequence($sequenceName);
                    }
                }
            }

            $platform = $connection->getDatabasePlatform();
            $up = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform));
            $down = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform));

            if (!$up && !$down) {
                return ['No changes detected in your mapping information.', null];
            }
        }

        return ['Generated new migration class!', $this->writeMigrationClassToFile($configuration, $up, $down)];
    }