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)];
    }
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)];
    }
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 ) ] ; }
Generates a new migration file and returns the path to it.

If $diffAgainstCurrent is true, it generates a migration file with the
diff between current DB structure and the found mapping metadata.

Only include tables/sequences matching the $filterExpression regexp when
diffing models and existing schema.

Otherwise an empty migration skeleton is generated.

@param boolean $diffAgainstCurrent
@param string $filterExpression
@return array Path to the new file
@throws DBALException
@throws \Doctrine\ORM\ORMException
@throws FilesException
Generates a new migration file and returns the path to it .