Skip to content

MSSQL removeColumn method fix for primaryKey column - #7081

Merged
sushantdhiman merged 4 commits into
sequelize:masterfrom
harshithkashyap:mssql-drop-primarykey-constraint
Jan 11, 2017
Merged

sushantdhiman merged 4 commits into
sequelize:masterfrom
harshithkashyap:mssql-drop-primarykey-constraint

Conversation

@harshithkashyap

@harshithkashyap harshithkashyap commented Jan 7, 2017 •

Copy link
Copy Markdown

Pull Request check-list

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does your issue contain a link to 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)?
  • Have you added an entry under Future in the changelog?

Description of change

When the removeColumn method is called on a primaryKey column, SQL Server errors as the primaryKey column has an associated constraint which should be dropped before dropping the primaryKey column.

@codecov-io

codecov-io commented Jan 7, 2017 •

Copy link
Copy Markdown

Current coverage is 94.82% (diff: 100%)

Merging #7081 into master will increase coverage by <.01%

Powered by Codecov. Last update 54556cc...cc85afc

@harshithkashyap

Copy link
Copy Markdown
Author

@janmeier @sushantdhiman @felixfbecker Request review

Comment thread lib/dialects/mssql/query-generator.js Outdated
return sql;
},

getPrimaryKeyConstraint(table, attributeName) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method only generates SQL, lets call it getPrimaryKeyConstraintQuery

Comment thread lib/dialects/mssql/query-generator.js Outdated

getPrimaryKeyConstraint(table, attributeName) {
const tableName = wrapSingleQuote(table.tableName || table);
const sql = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly return query without using sql variable :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sushantdhiman I wanted to keep the query readable yet copy pastable when logged so went for this. Using backticks keeps the same formatting as defined when logged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no issue with Array based query generation and joining it, I would mostly encourage it for query generation.

My point was you put join result in a variable and return that variable, why don't directly return output of join directly

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sure, I'll make the mentioned changes :)

});
});

it('Should be able to remove a column with primaryKey', function () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should => should

});
});

it('Should be able to remove a column with primaryKey', function () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should => should

@sushantdhiman
sushantdhiman merged commit 37e8402 into sequelize:master Jan 11, 2017
@harshithkashyap
harshithkashyap deleted the mssql-drop-primarykey-constraint branch January 12, 2017 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants