Skip to content

Commit

Permalink
Remove PostgreSQLPlatform::isNumericType()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed May 14, 2022
1 parent 0781235 commit b235356
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
39 changes: 2 additions & 37 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -522,7 +519,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());
Expand Down Expand Up @@ -1188,7 +1185,7 @@ public function getBlobTypeDeclarationSQL(array $column)
*/
public function getDefaultValueDeclarationSQL($column)
{
if ($this->isSerialColumn($column)) {
if (isset($column['autoincrement']) && $column['autoincrement'] === true) {
return '';
}

Expand Down Expand Up @@ -1223,38 +1220,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;
Expand Down
1 change: 0 additions & 1 deletion tests/Platforms/PostgreSQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b235356

Please sign in to comment.