Skip to content

Commit

Permalink
Merge branch 'bpo/2.8/#3158' into 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 16, 2018
2 parents 7d9f7d0 + 6ce2ef7 commit bfe33c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,14 @@ public function getAlterTableSQL(TableDiff $diff)
}
}

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
);
}

Expand Down Expand Up @@ -1254,4 +1257,9 @@ private function isNumericType(Type $type) : bool
{
return $type instanceof IntegerType || $type instanceof BigIntType;
}

private function getOldColumnComment(ColumnDiff $columnDiff) : ?string
{
return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,29 @@ protected function getAlterStringToFixedStringSQL()
);
}

/**
* @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}
*/
Expand Down

0 comments on commit bfe33c3

Please sign in to comment.