Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Exception/InvalidColumnDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,34 @@

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;
}
}
25 changes: 25 additions & 0 deletions src/Exception/InvalidColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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;
}
}
19 changes: 17 additions & 2 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -193,8 +195,21 @@ 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);
Expand Down