Commit eef9d760 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #294 from deeky666/fix-removing-column-comment

Allow removing column comment on some platforms
parents ecdb0696 ef57a35b
......@@ -571,9 +571,21 @@ LEFT JOIN user_cons_columns r_cols
}
$column = $columnDiff->column;
$columnHasChangedComment = $columnDiff->hasChanged('comment');
/**
* Do not add query part if only comment has changed
*/
if ( ! ($columnHasChangedComment && count($columnDiff->changedProperties) === 1)) {
$fields[] = $column->getQuotedName($this). ' ' . $this->getColumnDeclarationSQL('', $column->toArray());
if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
}
if ($columnHasChangedComment) {
$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->name,
$column->getName(),
$this->getColumnComment($column)
);
}
}
......
......@@ -432,8 +432,12 @@ class PostgreSqlPlatform extends AbstractPlatform
}
}
if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
if ($columnDiff->hasChanged('comment')) {
$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->name,
$column->getName(),
$this->getColumnComment($column)
);
}
if ($columnDiff->hasChanged('length')) {
......@@ -463,6 +467,16 @@ class PostgreSqlPlatform extends AbstractPlatform
return array_merge($sql, $tableSql, $columnSql);
}
/**
* {@inheritdoc}
*/
public function getCommentOnColumnSQL($tableName, $columnName, $comment)
{
$comment = $comment === null ? 'NULL' : "'$comment'";
return "COMMENT ON COLUMN $tableName.$columnName IS $comment";
}
/**
* {@inheritDoc}
*/
......
......@@ -535,6 +535,20 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$columns = $this->_sm->listTableColumns("column_comment_test");
$this->assertEquals(1, count($columns));
$this->assertEquals('This is a comment', $columns['id']->getComment());
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('column_comment_test');
$tableDiff->changedColumns['id'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'id', new \Doctrine\DBAL\Schema\Column(
'id', \Doctrine\DBAL\Types\Type::getType('integer'), array('primary' => true)
),
array('comment')
);
$this->_sm->alterTable($tableDiff);
$columns = $this->_sm->listTableColumns("column_comment_test");
$this->assertEquals(1, count($columns));
$this->assertEmpty($columns['id']->getComment());
}
/**
......
......@@ -374,6 +374,12 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
$tableDiff = new TableDiff('mytable');
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment'));
$tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'foo', new \Doctrine\DBAL\Schema\Column(
'foo', \Doctrine\DBAL\Types\Type::getType('string')
),
array('comment')
);
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'bar', new \Doctrine\DBAL\Schema\Column(
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment')
......
......@@ -203,7 +203,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
public function getAlterTableColumnCommentsSQL()
{
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
}
public function getCreateTableColumnTypeCommentsSQL()
......
......@@ -268,8 +268,8 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{
return array(
"ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)",
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) NOT NULL)",
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.foo IS ''",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
);
}
......
......@@ -254,6 +254,7 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
return array(
"ALTER TABLE mytable ADD quota INT NOT NULL",
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.foo IS NULL",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
);
}
......
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