protected function buildMigration(\Doctrine\DBAL\Schema\Schema $newSchema, \Doctrine\DBAL\Schema\Schema $oldSchema, $drop) {
		$comparator = new \Doctrine\DBAL\Schema\Comparator;
		$schemaDiff = $comparator->compare($oldSchema, $newSchema);

		$res = '';

		if($drop) {
			foreach($schemaDiff->removedTables as $tableName=>$table)
				$res .= $this->dropTable($tableName);
		}
		else {
			foreach($schemaDiff->newTables as $tableName=>$table)
				$res .= $this->createTable($tableName, $table);
		}

		foreach($schemaDiff->changedTables as $tableName=>$table) {
			$colsRes = '';

			foreach($table->addedColumns as $colName=>$col)
				$colsRes .= $this->createColumn($colName, $col);

			foreach($table->changedColumns as $colName=>$col)
				$colsRes .= $this->updateColumn($colName, $col);

			foreach($table->renamedColumns as $colName=>$col)
				$colsRes .= $this->renameColumn($colName, $col);

			foreach($table->removedColumns as $colName=>$col)
				$colsRes .= $this->dropColumn($colName);

			foreach($table->addedIndexes as $index)
				$colsRes .= $this->createIndex($index);

			foreach($table->removedIndexes as $indexName=>$index)
				$colsRes .= $this->dropIndex($indexName);

			foreach($table->addedForeignKeys as $key)
				$colsRes .= $this->createForeignKey($key);

			foreach($table->removedForeignKeys as $key)
				$colsRes .= $this->dropForeignKey($key);

			if($colsRes)
				$res .= "\$this->schema->table('$tableName', function(\$table) {".$colsRes."\n});\n\n";
		}

		return trim($res, "\n");
	}
protected function buildMigration(\Doctrine\DBAL\Schema\Schema $newSchema, \Doctrine\DBAL\Schema\Schema $oldSchema, $drop) {
		$comparator = new \Doctrine\DBAL\Schema\Comparator;
		$schemaDiff = $comparator->compare($oldSchema, $newSchema);

		$res = '';

		if($drop) {
			foreach($schemaDiff->removedTables as $tableName=>$table)
				$res .= $this->dropTable($tableName);
		}
		else {
			foreach($schemaDiff->newTables as $tableName=>$table)
				$res .= $this->createTable($tableName, $table);
		}

		foreach($schemaDiff->changedTables as $tableName=>$table) {
			$colsRes = '';

			foreach($table->addedColumns as $colName=>$col)
				$colsRes .= $this->createColumn($colName, $col);

			foreach($table->changedColumns as $colName=>$col)
				$colsRes .= $this->updateColumn($colName, $col);

			foreach($table->renamedColumns as $colName=>$col)
				$colsRes .= $this->renameColumn($colName, $col);

			foreach($table->removedColumns as $colName=>$col)
				$colsRes .= $this->dropColumn($colName);

			foreach($table->addedIndexes as $index)
				$colsRes .= $this->createIndex($index);

			foreach($table->removedIndexes as $indexName=>$index)
				$colsRes .= $this->dropIndex($indexName);

			foreach($table->addedForeignKeys as $key)
				$colsRes .= $this->createForeignKey($key);

			foreach($table->removedForeignKeys as $key)
				$colsRes .= $this->dropForeignKey($key);

			if($colsRes)
				$res .= "\$this->schema->table('$tableName', function(\$table) {".$colsRes."\n});\n\n";
		}

		return trim($res, "\n");
	}
protected function buildMigration ( \ Doctrine \ DBAL \ Schema \ Schema $ newSchema , \ Doctrine \ DBAL \ Schema \ Schema $ oldSchema , $ drop ) { $ comparator = new \ Doctrine \ DBAL \ Schema \ Comparator ; $ schemaDiff = $ comparator -> compare ( $ oldSchema , $ newSchema ) ; $ res = '' ; if ( $ drop ) { foreach ( $ schemaDiff -> removedTables as $ tableName => $ table ) $ res .= $ this -> dropTable ( $ tableName ) ; } else { foreach ( $ schemaDiff -> newTables as $ tableName => $ table ) $ res .= $ this -> createTable ( $ tableName , $ table ) ; } foreach ( $ schemaDiff -> changedTables as $ tableName => $ table ) { $ colsRes = '' ; foreach ( $ table -> addedColumns as $ colName => $ col ) $ colsRes .= $ this -> createColumn ( $ colName , $ col ) ; foreach ( $ table -> changedColumns as $ colName => $ col ) $ colsRes .= $ this -> updateColumn ( $ colName , $ col ) ; foreach ( $ table -> renamedColumns as $ colName => $ col ) $ colsRes .= $ this -> renameColumn ( $ colName , $ col ) ; foreach ( $ table -> removedColumns as $ colName => $ col ) $ colsRes .= $ this -> dropColumn ( $ colName ) ; foreach ( $ table -> addedIndexes as $ index ) $ colsRes .= $ this -> createIndex ( $ index ) ; foreach ( $ table -> removedIndexes as $ indexName => $ index ) $ colsRes .= $ this -> dropIndex ( $ indexName ) ; foreach ( $ table -> addedForeignKeys as $ key ) $ colsRes .= $ this -> createForeignKey ( $ key ) ; foreach ( $ table -> removedForeignKeys as $ key ) $ colsRes .= $ this -> dropForeignKey ( $ key ) ; if ( $ colsRes ) $ res .= "\$this->schema->table('$tableName', function(\$table) {" . $ colsRes . "\n});\n\n" ; } return trim ( $ res , "\n" ) ; }
Build the migration code by comparing the new schemas to the old ones.
@param  \Doctrine\DBAL\Schema\Schema $newSchema
@param  \Doctrine\DBAL\Schema\Schema $oldSchema
@param  boolean                      $drop       true to drop the old tables
@return string  migration code
Build the migration code by comparing the new schemas to the old ones .