Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling existing SQL Server column comment when other properties change #4315

Merged
merged 1 commit into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public function getAlterTableSQL(TableDiff $diff)
);
} elseif ($hasFromComment && ! $hasComment) {
$commentsSql[] = $this->getDropColumnCommentSQL($diff->name, $column->getQuotedName($this));
} elseif ($hasComment) {
} elseif (! $hasFromComment && $hasComment) {
$commentsSql[] = $this->getCreateColumnCommentSQL(
$diff->name,
$column->getQuotedName($this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,13 @@ public function testColumnComments(): void
$table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']);
$table->addColumn('commented_type', 'object');
$table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']);
$table->addColumn('commented_req_change_column', 'integer', ['comment' => 'Some comment', 'notnull' => true]);
$table->setPrimaryKey(['id']);

$this->schemaManager->createTable($table);

$columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment');
self::assertCount(12, $columns);
self::assertCount(13, $columns);
self::assertNull($columns['id']->getComment());
self::assertNull($columns['comment_null']->getComment());
self::assertNull($columns['comment_false']->getComment());
Expand All @@ -199,6 +200,7 @@ public function testColumnComments(): void
self::assertEquals('Doctrine 0wnz comments for reserved keyword columns!', $columns['[create]']->getComment());
self::assertNull($columns['commented_type']->getComment());
self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment());
self::assertEquals('Some comment', $columns['commented_req_change_column']->getComment());

$tableDiff = new TableDiff('sqlsrv_column_comment');
$tableDiff->fromTable = $table;
Expand Down Expand Up @@ -326,13 +328,29 @@ public function testColumnComments(): void
new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.'])
);

// Change column requirements without changing comment.
$tableDiff->changedColumns['commented_req_change_column'] = new ColumnDiff(
'commented_req_change_column',
new Column(
'commented_req_change_column',
Type::getType('integer'),
['comment' => 'Some comment', 'notnull' => true]
),
['notnull'],
new Column(
'commented_req_change_column',
Type::getType('integer'),
['comment' => 'Some comment', 'notnull' => false]
morozov marked this conversation as resolved.
Show resolved Hide resolved
),
);

$tableDiff->removedColumns['comment_integer_0']
= new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]);

$this->schemaManager->alterTable($tableDiff);

$columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment');
self::assertCount(23, $columns);
self::assertCount(24, $columns);
self::assertEquals('primary', $columns['id']->getComment());
self::assertNull($columns['comment_null']->getComment());
self::assertEquals('false', $columns['comment_false']->getComment());
Expand All @@ -356,6 +374,7 @@ public function testColumnComments(): void
self::assertEquals('666', $columns['[select]']->getComment());
self::assertNull($columns['added_commented_type']->getComment());
self::assertEquals('666', $columns['added_commented_type_with_comment']->getComment());
self::assertEquals('Some comment', $columns['commented_req_change_column']->getComment());
}

public function testPkOrdering(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1718,4 +1718,19 @@ private function expectCteWithMinAndMaxRowNums(
. ') AS doctrine_tbl WHERE doctrine_rownum >= %d AND doctrine_rownum <= %d ORDER BY doctrine_rownum ASC';
self::assertEquals(sprintf($pattern, $expectedSql, $expectedMin, $expectedMax), $sql);
}

public function testAlterTableWithSchemaSameColumnComments(): void
{
$tableDiff = new TableDiff('testschema.mytable');
$tableDiff->changedColumns['quota'] = new ColumnDiff(
'quota',
new Column('quota', Type::getType('integer'), ['comment' => 'A comment', 'notnull' => true]),
['notnull'],
new Column('quota', Type::getType('integer'), ['comment' => 'A comment', 'notnull' => false])
);

$expectedSql = ['ALTER TABLE testschema.mytable ALTER COLUMN quota INT NOT NULL'];

self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff));
}
}