From 806755b1d68981706ec547726fa7374edc139e02 Mon Sep 17 00:00:00 2001 From: Oleg Klimenko Date: Sun, 14 May 2017 23:23:56 +0300 Subject: [PATCH] Fix postgres quoting in comment clause --- src/Phinx/Db/Adapter/PostgresAdapter.php | 4 ++-- .../Phinx/Db/Adapter/PostgresAdapterTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 788c0b8a8..0e7814df5 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -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 ); } diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index bccdfab1b..4a4649096 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -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 */