Migrations\Shell\Task\MigrationDiffTask::getColumns PHP Method

getColumns() protected method

This will look for columns addition, columns removal and changes in columns metadata such as change of types or property such as length. Note that the method is not able to detect columns name change. The method directly sets the diff in a property of the class.
protected getColumns ( ) : void
return void
    protected function getColumns()
    {
        foreach ($this->commonTables as $table => $currentSchema) {
            $currentColumns = $currentSchema->columns();
            $oldColumns = $this->dumpSchema[$table]->columns();
            // brand new columns
            $addedColumns = array_diff($currentColumns, $oldColumns);
            foreach ($addedColumns as $columnName) {
                $this->templateData[$table]['columns']['add'][$columnName] = $currentSchema->column($columnName);
            }
            // changes in columns meta-data
            foreach ($currentColumns as $columnName) {
                $column = $currentSchema->column($columnName);
                unset($column['collate']);
                $oldColumn = $this->dumpSchema[$table]->column($columnName);
                if (in_array($columnName, $oldColumns) && $column !== $oldColumn) {
                    $changedAttributes = array_diff($column, $oldColumn);
                    if (!isset($changedAttributes['type'])) {
                        $changedAttributes['type'] = $column['type'];
                    }
                    $this->templateData[$table]['columns']['changed'][$columnName] = $changedAttributes;
                }
            }
            // columns deletion
            if (!isset($this->templateData[$table]['columns']['remove'])) {
                $this->templateData[$table]['columns']['remove'] = [];
            }
            $removedColumns = array_diff($oldColumns, $currentColumns);
            if (!empty($removedColumns)) {
                foreach ($removedColumns as $column) {
                    $this->templateData[$table]['columns']['remove'][$column] = $this->dumpSchema[$table]->column($column);
                }
            }
        }
    }