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 pgsql quoting in comment clause #1091

Merged
merged 1 commit into from
Jul 23, 2017
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
4 changes: 2 additions & 2 deletions src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,8 @@ protected function getColumnCommentSqlDefinition(Column $column, $tableName)

return sprintf(
'COMMENT ON COLUMN %s.%s IS %s;',
$tableName,
$column->getName(),
$this->quoteSchemaName($tableName),
$this->quoteColumnName($column->getName()),
$comment
);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,27 @@ public function testCanAddColumnComment()
$this->assertEquals($comment, $row['column_comment'], 'Dont set column comment correctly');
}

public function testCanAddCommentForColumnWithReservedName()
{
$table = new \Phinx\Db\Table('user', array(), $this->adapter);
$table->addColumn('index', 'string', array('comment' => $comment = 'Comments from column "index"'))
->save();

$row = $this->adapter->fetchRow(
'SELECT
(select pg_catalog.col_description(oid,cols.ordinal_position::int)
from pg_catalog.pg_class c
where c.relname=cols.table_name ) as column_comment
FROM information_schema.columns cols
WHERE cols.table_catalog=\''. TESTS_PHINX_DB_ADAPTER_POSTGRES_DATABASE .'\'
AND cols.table_name=\'user\'
AND cols.column_name = \'index\''
);

$this->assertEquals($comment, $row['column_comment'],
'Dont set column comment correctly for tables or columns with reserved names');
}

/**
* @depends testCanAddColumnComment
*/
Expand Down