diff --git a/typo3/sysext/core/Classes/Database/Schema/Comparator.php b/typo3/sysext/core/Classes/Database/Schema/Comparator.php index 8a09ef9491dba2f515c5e225cdb61252779c5831..f21f255702b64234ca434b82ba51257e74b2479e 100644 --- a/typo3/sysext/core/Classes/Database/Schema/Comparator.php +++ b/typo3/sysext/core/Classes/Database/Schema/Comparator.php @@ -15,7 +15,11 @@ namespace TYPO3\CMS\Core\Database\Schema; * The TYPO3 project - inspiring people to share! */ +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -25,6 +29,21 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; */ class Comparator extends \Doctrine\DBAL\Schema\Comparator { + /** + * @var AbstractPlatform + */ + protected $databasePlatform; + + /** + * Comparator constructor. + * + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + */ + public function __construct(AbstractPlatform $platform = null) + { + $this->databasePlatform = $platform; + } + /** * Returns the difference between the tables $fromTable and $toTable. * @@ -69,4 +88,38 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator return $tableDifferences; } + + /** + * Returns the difference between the columns $column1 and $column2 + * by first checking the doctrine diffColumn. Extend the Doctrine + * method by taking into account MySQL TINY/MEDIUM/LONG type variants. + * + * @param \Doctrine\DBAL\Schema\Column $column1 + * @param \Doctrine\DBAL\Schema\Column $column2 + * @return array + */ + public function diffColumn(Column $column1, Column $column2) + { + $changedProperties = parent::diffColumn($column1, $column2); + + // Only MySQL has variable length versions of TEXT/BLOB + if (!$this->databasePlatform instanceof MySqlPlatform) { + return $changedProperties; + } + + $properties1 = $column1->toArray(); + $properties2 = $column2->toArray(); + + if ($properties1['type'] instanceof Types\BlobType || $properties1['type'] instanceof Types\TextType) { + // Doctrine does not provide a length for LONGTEXT/LONGBLOB columns + $length1 = $properties1['length'] ?: 2147483647; + $length2 = $properties2['length'] ?: 2147483647; + + if ($length1 !== $length2) { + $changedProperties[] = 'length'; + } + } + + return array_unique($changedProperties); + } } diff --git a/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php b/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php index 46f63bc5e79078c825ba202156fd48006ad692b0..d2ebdcc826c57334328f8dfef840355dc8e8caca 100644 --- a/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php +++ b/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php @@ -224,8 +224,9 @@ class ConnectionMigrator * for tables that are in the database but have no direct relation to the TYPO3 instance. * * @param bool $renameUnused - * @return \Doctrine\DBAL\Schema\SchemaDiff * @throws \Doctrine\DBAL\DBALException + * @return \Doctrine\DBAL\Schema\SchemaDiff + * @throws \Doctrine\DBAL\Schema\SchemaException * @throws \InvalidArgumentException */ protected function buildSchemaDiff(bool $renameUnused = true): SchemaDiff @@ -247,7 +248,7 @@ class ConnectionMigrator } // Build SchemaDiff and handle renames of tables and colums - $comparator = GeneralUtility::makeInstance(Comparator::class); + $comparator = GeneralUtility::makeInstance(Comparator::class, $this->connection->getDatabasePlatform()); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $schemaDiff = $this->migrateColumnRenamesToDistinctActions($schemaDiff);