-
Notifications
You must be signed in to change notification settings - Fork 891
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
Added saving column's comment for PostgresAdapter when you add column #1246
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1246 +/- ##
==========================================
+ Coverage 72.32% 72.34% +0.01%
==========================================
Files 35 35
Lines 5551 5554 +3
==========================================
+ Hits 4015 4018 +3
Misses 1536 1536
Continue to review full report at Codecov.
|
$this->quoteTableName($table->getName()), | ||
$this->quoteColumnName($column->getName()), | ||
$this->getColumnSqlDefinition($column) | ||
); | ||
|
||
if ($column->getComment()) { | ||
$sql .= $this->getColumnCommentSqlDefinition($column, $table->getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be done in the getColumnSqlDefinition()
method, like MysqlAdapter
:
phinx/src/Phinx/Db/Adapter/MysqlAdapter.php
Lines 1005 to 1007 in d84a6c7
if ($column->getComment()) { | |
$def .= ' COMMENT ' . $this->getConnection()->quote($column->getComment()); | |
} |
and
SQLiteAdapter
:phinx/src/Phinx/Db/Adapter/SQLiteAdapter.php
Line 995 in d84a6c7
$def .= $this->getCommentDefinition($column); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that PostgreSQL requires additional (separate) request for adding a comment for a column.
For example:
- MySQL: "ALTER TABLE books ADD COLUMN author int(10) unsigned NOT NULL COMMENT 'a new comment';"
- PostgreSQL: "ALTER TABLE books ADD COLUMN author int NOT NULL;" + "COMMENT ON COLUMN books.author IS 'a new comment';"
If we add this logic into getColumnSqlDefinition() its behavior will be much different from the same methods in other adapters.
Comments treated this way in other methods, for example, createTable() adds comments only after column definitions:
phinx/src/Phinx/Db/Adapter/PostgresAdapter.php
Lines 201 to 208 in d84a6c7
foreach ($columns as $column) { | |
$sql .= $this->quoteColumnName($column->getName()) . ' ' . $this->getColumnSqlDefinition($column) . ', '; | |
// set column comments, if needed | |
if ($column->getComment()) { | |
$this->columnsWithComments[] = $column; | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation. You are right.
No description provided.