Unverified Commit 79e6d130 authored by Christopher Davis's avatar Christopher Davis Committed by Luís Cobucci

Don't Set a Default Value on Serial Fields When `notnull` is Set

Serial fields already have a default value. By opting out of `notnull`
serial fields will just set the next value in the sequence.
parent 288264d1
...@@ -26,7 +26,9 @@ use Doctrine\DBAL\Schema\Index; ...@@ -26,7 +26,9 @@ use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BinaryType;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\IntegerType;
/** /**
* PostgreSqlPlatform. * PostgreSqlPlatform.
...@@ -1186,4 +1188,22 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -1186,4 +1188,22 @@ class PostgreSqlPlatform extends AbstractPlatform
return parent::quoteStringLiteral($str); return parent::quoteStringLiteral($str);
} }
/**
* {@inheritdoc}
*/
public function getDefaultValueDeclarationSQL($field)
{
if ($this->isSerialField($field)) {
return '';
}
return parent::getDefaultValueDeclarationSQL($field);
}
private function isSerialField(array $field) : bool
{
return $field['autoincrement'] ?? false === true && isset($field['type'])
&& ($field['type'] instanceof IntegerType || $field['type'] instanceof BigIntType);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment