classes/TableMigrationCodeGenerator.php
public function createOrUpdateTable($updatedTable, $existingTable, $newTableName)
    {
        $tableDiff = false;

        if ($existingTable !== null) {
            /*
             * The table already exists
             */
            $comparator = new Comparator();
            $tableDiff = $comparator->diffTable($existingTable, $updatedTable);

            if ($newTableName !== $existingTable->getName()) {
                if (!$tableDiff) {
                    $tableDiff = new TableDiff($existingTable->getName());
                }

                $tableDiff->newName = $newTableName;
            }
        }
        else {
            /*
             * The table doesn't exist
             */
            $tableDiff = new TableDiff(
                $updatedTable->getName(),
                $updatedTable->getColumns(),
                [], // Changed columns
                [], // Removed columns
                $updatedTable->getIndexes() // Added indexes
            );

            $tableDiff->fromTable = $updatedTable;
        }

        if (!$tableDiff) {
            return false;
        }

        if (!$this->tableHasNameOrColumnChanges($tableDiff) && !$this->tableHasPrimaryKeyChanges($tableDiff)) {
            return false;
        }

        return $this->generateCreateOrUpdateCode($tableDiff, !$existingTable, $updatedTable);
    }
public function createOrUpdateTable($updatedTable, $existingTable, $newTableName)
    {
        $tableDiff = false;

        if ($existingTable !== null) {
            /*
             * The table already exists
             */
            $comparator = new Comparator();
            $tableDiff = $comparator->diffTable($existingTable, $updatedTable);

            if ($newTableName !== $existingTable->getName()) {
                if (!$tableDiff) {
                    $tableDiff = new TableDiff($existingTable->getName());
                }

                $tableDiff->newName = $newTableName;
            }
        }
        else {
            /*
             * The table doesn't exist
             */
            $tableDiff = new TableDiff(
                $updatedTable->getName(),
                $updatedTable->getColumns(),
                [], // Changed columns
                [], // Removed columns
                $updatedTable->getIndexes() // Added indexes
            );

            $tableDiff->fromTable = $updatedTable;
        }

        if (!$tableDiff) {
            return false;
        }

        if (!$this->tableHasNameOrColumnChanges($tableDiff) && !$this->tableHasPrimaryKeyChanges($tableDiff)) {
            return false;
        }

        return $this->generateCreateOrUpdateCode($tableDiff, !$existingTable, $updatedTable);
    }
public function createOrUpdateTable ( $ updatedTable , $ existingTable , $ newTableName ) { $ tableDiff = false ; if ( $ existingTable !== null ) { /*
             * The table already exists
             */ $ comparator = new Comparator ( ) ; $ tableDiff = $ comparator -> diffTable ( $ existingTable , $ updatedTable ) ; if ( $ newTableName !== $ existingTable -> getName ( ) ) { if ( ! $ tableDiff ) { $ tableDiff = new TableDiff ( $ existingTable -> getName ( ) ) ; } $ tableDiff -> newName = $ newTableName ; } } else { /*
             * The table doesn't exist
             */ $ tableDiff = new TableDiff ( $ updatedTable -> getName ( ) , $ updatedTable -> getColumns ( ) , [ ] , // Changed columns [ ] , // Removed columns $ updatedTable -> getIndexes ( ) // Added indexes ) ; $ tableDiff -> fromTable = $ updatedTable ; } if ( ! $ tableDiff ) { return false ; } if ( ! $ this -> tableHasNameOrColumnChanges ( $ tableDiff ) && ! $ this -> tableHasPrimaryKeyChanges ( $ tableDiff ) ) { return false ; } return $ this -> generateCreateOrUpdateCode ( $ tableDiff , ! $ existingTable , $ updatedTable ) ; }
Generates code for creating or updating a database table.
@param \Doctrine\DBAL\Schema\Table $updatedTable Specifies the updated table schema.
@param \Doctrine\DBAL\Schema\Table $existingTable Specifies the existing table schema, if applicable.
@param string $newTableName An updated name of the theme.
@return string|boolean Returns the migration up() and down() methods code.
Returns false if there the table was not changed.
Generates code for creating or updating a database table .