From 7fa039335187a4c0aa198d67bae2cdb1b7131efe Mon Sep 17 00:00:00 2001 From: Adrian Schenk <118049326+adrian-schenk@users.noreply.github.com> Date: Sun, 14 Jun 2026 14:23:22 +0200 Subject: [PATCH 1/2] feat: output table and column when an InvalidColumnDeclaration occurs --- src/Exception/InvalidColumnDeclaration.php | 25 +++++++++++++++++++++- src/Exception/InvalidColumnType.php | 21 ++++++++++++++++++ src/Schema/Comparator.php | 18 ++++++++++++++-- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Exception/InvalidColumnDeclaration.php b/src/Exception/InvalidColumnDeclaration.php index de68f4cf2f6..001ada50204 100644 --- a/src/Exception/InvalidColumnDeclaration.php +++ b/src/Exception/InvalidColumnDeclaration.php @@ -11,8 +11,31 @@ final class InvalidColumnDeclaration extends LogicException implements Exception { + + public string $column; + public string $table; + public static function fromInvalidColumnType(string $columnName, InvalidColumnType $e): self { - return new self(sprintf('Column "%s" has invalid type', $columnName), 0, $e); + $e->setColumn($columnName); + return (new self('Column "%s" has invalid type', 0, $e))->setColumn($columnName); + } + + public function setColumn(string $column): self + { + $this->column = $column; + return $this; + } + + public function setTable(string $table): self + { + $this->table = $table; + return $this; + } + + public function updateErrorMessage(): self + { + $this->message = sprintf('Column "%s" in table "%s" has invalid type', $this->column, $this->table); + return $this; } } diff --git a/src/Exception/InvalidColumnType.php b/src/Exception/InvalidColumnType.php index b2a3e453414..136c166c864 100644 --- a/src/Exception/InvalidColumnType.php +++ b/src/Exception/InvalidColumnType.php @@ -9,4 +9,25 @@ abstract class InvalidColumnType extends LogicException implements Exception { + public string $tableName; + public string $columnName; + + public function updateErrorMessage(): self + { + $this->message = sprintf('Column "%s" in table "%s": %s', $this->columnName, $this->tableName, $this->message); + return $this; + } + + public function setTable(string $table): self + { + $this->tableName = $table; + return $this; + } + + public function setColumn(string $column): self + { + $this->columnName = $column; + return $this; + } + } diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 2f0a949bbbb..6cfc8524b56 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\Exception\InvalidColumnDeclaration; +use Doctrine\DBAL\Exception\InvalidColumnType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Deprecations\Deprecation; @@ -193,8 +195,20 @@ public function compareTables(Table $oldTable, Table $newTable): TableDiff $newColumn = $newTable->getColumn($oldColumnName); - if ($this->columnsEqual($oldColumn, $newColumn)) { - continue; + try { + if ($this->columnsEqual($oldColumn, $newColumn)) { + continue; + } + } catch (InvalidColumnDeclaration $e) { + $newTableName = $newTable->getObjectName()->toString(); + $e->setTable($newTableName) + ->updateErrorMessage(); + $prev = $e->getPrevious(); + if ($prev instanceof InvalidColumnType) { + $prev->setTable($newTableName); + $prev->updateErrorMessage(); + } + throw $e; } $modifiedColumns[$oldColumnName] = new ColumnDiff($oldColumn, $newColumn); From 655c51b37ffd4ac4b0374508fdb94d62fa5235a5 Mon Sep 17 00:00:00 2001 From: Adrian Schenk <118049326+adrian-schenk@users.noreply.github.com> Date: Sun, 14 Jun 2026 20:21:07 +0200 Subject: [PATCH 2/2] fix coding standards checks --- src/Exception/InvalidColumnDeclaration.php | 5 ++- src/Exception/InvalidColumnType.php | 44 ++++++++++++---------- src/Schema/Comparator.php | 1 + 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/Exception/InvalidColumnDeclaration.php b/src/Exception/InvalidColumnDeclaration.php index 001ada50204..5d0a3d7208a 100644 --- a/src/Exception/InvalidColumnDeclaration.php +++ b/src/Exception/InvalidColumnDeclaration.php @@ -11,31 +11,34 @@ final class InvalidColumnDeclaration extends LogicException implements Exception { - public string $column; public string $table; public static function fromInvalidColumnType(string $columnName, InvalidColumnType $e): self { $e->setColumn($columnName); + return (new self('Column "%s" has invalid type', 0, $e))->setColumn($columnName); } public function setColumn(string $column): self { $this->column = $column; + return $this; } public function setTable(string $table): self { $this->table = $table; + return $this; } public function updateErrorMessage(): self { $this->message = sprintf('Column "%s" in table "%s" has invalid type', $this->column, $this->table); + return $this; } } diff --git a/src/Exception/InvalidColumnType.php b/src/Exception/InvalidColumnType.php index 136c166c864..4d8454ba436 100644 --- a/src/Exception/InvalidColumnType.php +++ b/src/Exception/InvalidColumnType.php @@ -7,27 +7,31 @@ use Doctrine\DBAL\Exception; use LogicException; +use function sprintf; + abstract class InvalidColumnType extends LogicException implements Exception { - public string $tableName; - public string $columnName; - - public function updateErrorMessage(): self - { - $this->message = sprintf('Column "%s" in table "%s": %s', $this->columnName, $this->tableName, $this->message); - return $this; - } - - public function setTable(string $table): self - { - $this->tableName = $table; - return $this; - } - - public function setColumn(string $column): self - { - $this->columnName = $column; - return $this; - } + public string $tableName; + public string $columnName; + + public function updateErrorMessage(): self + { + $this->message = sprintf('Column "%s" in table "%s": %s', $this->columnName, $this->tableName, $this->message); + + return $this; + } + + public function setTable(string $table): self + { + $this->tableName = $table; + + return $this; + } + + public function setColumn(string $column): self + { + $this->columnName = $column; + return $this; + } } diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 6cfc8524b56..d09eca64c6f 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -208,6 +208,7 @@ public function compareTables(Table $oldTable, Table $newTable): TableDiff $prev->setTable($newTableName); $prev->updateErrorMessage(); } + throw $e; }