2 declare(strict_types = 1);
18 use Doctrine\DBAL\Platforms\AbstractPlatform;
19 use Doctrine\DBAL\Platforms\MySqlPlatform;
20 use Doctrine\DBAL\Schema\Column;
21 use Doctrine\DBAL\Schema\Table;
22 use Doctrine\DBAL\Types;
42 public function __construct(AbstractPlatform $platform =
null)
44 $this->databasePlatform = $platform;
57 public function diffTable(Table $fromTable, Table $toTable)
59 $newTableOptions = array_merge($fromTable->getOptions(), $toTable->getOptions());
60 $optionDiff = array_diff_assoc($newTableOptions, $fromTable->getOptions());
61 $tableDifferences = parent::diffTable($fromTable, $toTable);
64 if (count($optionDiff) === 0) {
65 return $tableDifferences;
68 if ($tableDifferences ===
false) {
69 $tableDifferences = GeneralUtility::makeInstance(TableDiff::class, $fromTable->getName());
70 $tableDifferences->fromTable = $fromTable;
72 $renamedColumns = $tableDifferences->renamedColumns;
73 $renamedIndexes = $tableDifferences->renamedIndexes;
75 $tableDifferences = GeneralUtility::makeInstance(
77 $tableDifferences->name,
78 $tableDifferences->addedColumns,
79 $tableDifferences->changedColumns,
80 $tableDifferences->removedColumns,
81 $tableDifferences->addedIndexes,
82 $tableDifferences->changedIndexes,
83 $tableDifferences->removedIndexes,
84 $tableDifferences->fromTable
86 $tableDifferences->renamedColumns = $renamedColumns;
87 $tableDifferences->renamedIndexes = $renamedIndexes;
91 $tableDifferences->setTableOptions($optionDiff);
93 return $tableDifferences;
105 public function diffColumn(Column $column1, Column $column2)
107 $changedProperties = parent::diffColumn($column1, $column2);
110 if (!$this->databasePlatform instanceof MySqlPlatform) {
111 return $changedProperties;
114 $properties1 = $column1->toArray();
115 $properties2 = $column2->toArray();
117 if ($properties1[
'type'] instanceof Types\BlobType || $properties1[
'type'] instanceof Types\TextType) {
119 $length1 = $properties1[
'length'] ?: 2147483647;
120 $length2 = $properties2[
'length'] ?: 2147483647;
122 if ($length1 !== $length2) {
123 $changedProperties[] =
'length';
127 return array_unique($changedProperties);