Unverified Commit ff30f9aa authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3158 from bendavies/postgres-alter-table-column-comment

postgres: correctly produce alter table sql comment to update column definition
parents 6f627e6d 8a7208d1
......@@ -580,11 +580,14 @@ SQL
}
}
if ($columnDiff->hasChanged('comment')) {
$newComment = $this->getColumnComment($column);
$oldComment = $this->getOldColumnComment($columnDiff);
if ($columnDiff->hasChanged('comment') || ($columnDiff->fromColumn !== null && $oldComment !== $newComment)) {
$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this),
$column->getQuotedName($this),
$this->getColumnComment($column)
$newComment
);
}
......@@ -1248,4 +1251,9 @@ SQL
{
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
);
}
/**
* @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}
*/
......
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