Unverified Commit 1b7abb4b authored by Ben Davies's avatar Ben Davies Committed by Sergei Morozov

correctly produce alter table sql to update column comment under postgres

parent 7d9f7d0e
...@@ -591,11 +591,17 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -591,11 +591,17 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
} }
if ($columnDiff->hasChanged('comment')) { $oldComment = null;
$newComment = $this->getColumnComment($column);
if (null !== $columnDiff->fromColumn) {
$oldComment = $this->getColumnComment($columnDiff->fromColumn);
}
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
); );
} }
......
...@@ -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