Skip to content

Commit

Permalink
correctly produce alter table sql to update column comment under post…
Browse files Browse the repository at this point in the history
…gres
  • Loading branch information
bendavies committed May 21, 2018
1 parent 3591db5 commit 63ff2c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,14 @@ public function getAlterTableSQL(TableDiff $diff)
}
}

if ($columnDiff->hasChanged('comment')) {
$oldComment = $this->getColumnComment($columnDiff->fromColumn);
$newComment = $this->getColumnComment($column);

if ($oldComment !== $newComment) {
$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this),
$column->getQuotedName($this),
$this->getColumnComment($column)
$newComment
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,29 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers()
);
}

/**
* @group 3158
*/
public function testAltersTableColumnCommentIfRequiredByType()
{
$table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('datetime'))));
$table2 = new Table('"foo"', array(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}
*/
Expand Down

0 comments on commit 63ff2c5

Please sign in to comment.