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(query-generator): fix addColumn create comment #10117



Copy link

@mirkojotic mirkojotic commented Nov 3, 2018

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in

Description of change

Resolves #4386
More specifically #4386 (comment)
This adds on the work @theRichu started around adding an ability to add a comment while using addColumn API.

Initial PR can be found here

@mirkojotic mirkojotic changed the title Add comment on add column fix(query-generator): fix addColumn create comment Nov 3, 2018
Copy link

@codecov codecov bot commented Nov 3, 2018

Codecov Report

Merging #10117 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10117      +/-   ##
- Coverage   96.37%   96.33%   -0.05%     
  Files          63       63              
  Lines        9411     9431      +20     
+ Hits         9070     9085      +15     
- Misses        341      346       +5
Impacted Files Coverage Δ
lib/dialects/mssql/query-generator.js 95.83% <100%> (+0.05%) ⬆️
lib/dialects/postgres/query-generator.js 94.08% <100%> (+0.06%) ⬆️
lib/utils.js 98.28% <0%> (-0.02%) ⬇️
lib/data-types.js 95.14% <0%> (-0.02%) ⬇️
lib/dialects/abstract/connection-manager.js 90% <0%> (ø) ⬆️
lib/hooks.js 97.05% <0%> (ø) ⬆️
lib/dialects/postgres/query.js 97.44% <0%> (ø) ⬆️
lib/dialects/postgres/range.js 100% <0%> (ø) ⬆️
lib/dialects/sqlite/data-types.js 97.15% <0%> (ø) ⬆️
lib/dialects/mssql/connection-manager.js 88.6% <0%> (ø) ⬆️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3af0537...43790bd. Read the comment docs.

Copy link

@sushantdhiman sushantdhiman left a comment

LGTM, just a small change

lib/dialects/postgres/query-generator.js Outdated Show resolved Hide resolved
@sushantdhiman sushantdhiman merged commit b896ba4 into sequelize:master Nov 5, 2018
4 checks passed
4 checks passed
codecov/patch 100% of diff hit (target 96.37%)
codecov/project Absolute coverage decreased by -0.04% but relative coverage increased by +3.62% compared to 3af0537
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
Copy link

@sushantdhiman sushantdhiman commented Nov 5, 2018

Thanks @mirkojotic

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}`;

This comment has been minimized.


normancarcamo Nov 14, 2018

Is this feature working?
I need to put some comments into a column to let know others devs of a team a small description of what's the purpose of the column.

This comment has been minimized.


mirkojotic Nov 15, 2018
Author Contributor

@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 addColumn API of query generator.

@@ -239,11 +234,28 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
// FIXME: attributeToSQL SHOULD be using attributes in addColumnQuery
// but instead we need to pass the key along as the field here
dataType.field = key;
let commentStr = '';

if (dataType.comment && _.isString(dataType.comment)) {

This comment has been minimized.


SimonSchick Nov 15, 2018

Post merge comment: Should use typeof

This comment has been minimized.


mirkojotic Nov 15, 2018
Author Contributor

@SimonSchick Agreed. I was trying to be consistent with the rest of the codebase and lodash is already imported and used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants