diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index 74cf7eda9dd..7db8bf249ad 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -9,11 +9,8 @@ use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\TableDiff; -use Doctrine\DBAL\Types\BigIntType; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BlobType; -use Doctrine\DBAL\Types\IntegerType; -use Doctrine\DBAL\Types\Type; use Doctrine\Deprecations\Deprecation; use UnexpectedValueException; @@ -533,7 +530,7 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } - if ($columnDiff->hasChanged('default') || $this->typeChangeBreaksDefaultValue($columnDiff)) { + if ($columnDiff->hasChanged('default')) { $defaultClause = $column->getDefault() === null ? ' DROP DEFAULT' : ' SET' . $this->getDefaultValueDeclarationSQL($column->toArray()); @@ -1221,7 +1218,7 @@ public function getBlobTypeDeclarationSQL(array $column) */ public function getDefaultValueDeclarationSQL($column) { - if ($this->isSerialColumn($column)) { + if (isset($column['autoincrement']) && $column['autoincrement'] === true) { return ''; } @@ -1256,38 +1253,6 @@ public function getJsonTypeDeclarationSQL(array $column) return 'JSON'; } - /** - * @param mixed[] $column - */ - private function isSerialColumn(array $column): bool - { - return isset($column['type'], $column['autoincrement']) - && $column['autoincrement'] === true - && $this->isNumericType($column['type']); - } - - /** - * Check whether the type of a column is changed in a way that invalidates the default value for the column - */ - private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff): bool - { - if ($columnDiff->fromColumn === null) { - return $columnDiff->hasChanged('type'); - } - - $oldTypeIsNumeric = $this->isNumericType($columnDiff->fromColumn->getType()); - $newTypeIsNumeric = $this->isNumericType($columnDiff->column->getType()); - - // default should not be changed when switching between numeric types and the default comes from a sequence - return $columnDiff->hasChanged('type') - && ! ($oldTypeIsNumeric && $newTypeIsNumeric && $columnDiff->column->getAutoincrement()); - } - - private function isNumericType(Type $type): bool - { - return $type instanceof IntegerType || $type instanceof BigIntType; - } - private function getOldColumnComment(ColumnDiff $columnDiff): ?string { return $columnDiff->fromColumn !== null ? $this->getColumnComment($columnDiff->fromColumn) : null; diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index 1f731d50558..407dbef47bf 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -891,7 +891,6 @@ public function testAltersTableColumnCommentIfRequiredByType(): void self::assertSame( [ 'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', - 'ALTER TABLE "foo" ALTER "bar" DROP DEFAULT', 'COMMENT ON COLUMN "foo"."bar" IS \'(DC2Type:datetime_immutable)\'', ], $this->platform->getAlterTableSQL($tableDiff)