Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow removing column comment on some platforms #294

Merged
merged 1 commit into from

3 participants

@deeky666
Collaborator

Some platforms currently do not remove a comment on a column on table alteration.
This PR fixes this. Also updated platform and functional schema tests for this.
Besides that OraclePlatform now does not generate a useless ALTER TABLE MODIFY SQL snippet when only the column comment has changed, as this is handled seperately through COMMENT ON COLUMN SQL statement.

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-476

@beberlei beberlei merged commit eef9d76 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @deeky666
This page is out of date. Refresh to see the latest.
View
18 lib/Doctrine/DBAL/Platforms/OraclePlatform.php
@@ -571,9 +571,21 @@ public function getAlterTableSQL(TableDiff $diff)
}
$column = $columnDiff->column;
- $fields[] = $column->getQuotedName($this). ' ' . $this->getColumnDeclarationSQL('', $column->toArray());
- if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
- $commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
+ $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 ($columnHasChangedComment) {
+ $commentsSQL[] = $this->getCommentOnColumnSQL(
+ $diff->name,
+ $column->getName(),
+ $this->getColumnComment($column)
+ );
}
}
View
18 lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
@@ -432,8 +432,12 @@ public function getAlterTableSQL(TableDiff $diff)
}
}
- 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')) {
@@ -464,6 +468,16 @@ public function getAlterTableSQL(TableDiff $diff)
}
/**
+ * {@inheritdoc}
+ */
+ public function getCommentOnColumnSQL($tableName, $columnName, $comment)
+ {
+ $comment = $comment === null ? 'NULL' : "'$comment'";
+
+ return "COMMENT ON COLUMN $tableName.$columnName IS $comment";
+ }
+
+ /**
* {@inheritDoc}
*/
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
View
14 tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
@@ -535,6 +535,20 @@ public function testGetColumnComment()
$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());
}
/**
View
6 tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
@@ -374,6 +374,12 @@ public function testAlterTableColumnComments()
{
$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')
View
2  tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
@@ -203,7 +203,7 @@ public function getCreateTableColumnCommentsSQL()
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()
View
2  tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
@@ -268,8 +268,8 @@ public function getAlterTableColumnCommentsSQL()
{
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'",
);
}
View
1  tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
@@ -254,6 +254,7 @@ public function getAlterTableColumnCommentsSQL()
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'",
);
}
Something went wrong with that request. Please try again.