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(query-generator): fix addColumn create comment #10117
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,7 +244,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { | |
|
||
addColumnQuery(table, key, dataType) { | ||
|
||
const dbDataType = this.attributeToSQL(dataType, { context: 'addColumn' }); | ||
const dbDataType = this.attributeToSQL(dataType, { context: 'addColumn', table, key }); | ||
const definition = this.dataTypeMapping(table, key, dbDataType); | ||
const quotedKey = this.quoteIdentifier(key); | ||
const quotedTable = this.quoteTable(this.extractTableDetails(table)); | ||
|
@@ -452,7 +452,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { | |
return fragment; | ||
} | ||
|
||
attributeToSQL(attribute) { | ||
attributeToSQL(attribute, option) { | ||
mirkojotic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!_.isPlainObject(attribute)) { | ||
attribute = { | ||
type: attribute | ||
|
@@ -535,7 +535,13 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { | |
} | ||
|
||
if (attribute.comment && _.isString(attribute.comment)) { | ||
sql += ` COMMENT ${attribute.comment}`; | ||
if (option && option.context === 'addColumn') { | ||
const quotedAttr = this.quoteIdentifier(option.key); | ||
const escapedCommentText = this.escape(attribute.comment); | ||
sql += `; COMMENT ON COLUMN ${this.quoteTable(option.table)}.${quotedAttr} IS ${escapedCommentText}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this feature working? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @normancarcamo It was merged into master but you'll have to see which version of sequelize it will land in. But also this is just the the addition to a PR merged a couple of months back that allowed this to be done on table creation. This PR is just so you could leverage this feature on |
||
} else { | ||
sql += ` COMMENT ${attribute.comment}`; | ||
} | ||
} | ||
|
||
return sql; | ||
|
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.
Post merge comment: Should use
typeof
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.
@SimonSchick Agreed. I was trying to be consistent with the rest of the codebase and lodash is already imported and used.