Unverified Commit bfe33c3e authored by Sergei Morozov's avatar Sergei Morozov

Merge branch 'bpo/2.8/#3158' into 2.8

parents 7d9f7d0e 6ce2ef72
...@@ -591,11 +591,14 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -591,11 +591,14 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
} }
if ($columnDiff->hasChanged('comment')) { $newComment = $this->getColumnComment($column);
$oldComment = $this->getOldColumnComment($columnDiff);
if ($columnDiff->hasChanged('comment') || ($columnDiff->fromColumn !== null && $oldComment !== $newComment)) {
$commentsSQL[] = $this->getCommentOnColumnSQL( $commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this), $diff->getName($this)->getQuotedName($this),
$column->getQuotedName($this), $column->getQuotedName($this),
$this->getColumnComment($column) $newComment
); );
} }
...@@ -1254,4 +1257,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -1254,4 +1257,9 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return $type instanceof IntegerType || $type instanceof BigIntType; return $type instanceof IntegerType || $type instanceof BigIntType;
} }
private function getOldColumnComment(ColumnDiff $columnDiff) : ?string
{
return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null;
}
} }
...@@ -853,6 +853,29 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -853,6 +853,29 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
); );
} }
/**
* @group 3158
*/
public function testAltersTableColumnCommentIfRequiredByType()
{
$table1 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime'))]);
$table2 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime_immutable'))]);
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($table1, $table2);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->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)
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
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