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

MSSQL removeColumn method fix for primaryKey column #7081

Merged
merged 4 commits into from Jan 11, 2017

Conversation

4 participants
@harshithkashyap
Member

harshithkashyap commented Jan 7, 2017

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.

  • Added getPrimaryKeyConstraint method to retrieve primary key constraint based on tableName and columnName.
  • Extends #4943
@codecov-io

This comment has been minimized.

codecov-io commented Jan 7, 2017

Current coverage is 94.82% (diff: 100%)

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

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

@harshithkashyap harshithkashyap force-pushed the harshithkashyap:mssql-drop-primarykey-constraint branch from ace2fc6 to f1a159e Jan 7, 2017

@harshithkashyap

This comment has been minimized.

Member

harshithkashyap commented Jan 10, 2017

@@ -680,6 +680,25 @@ var QueryGenerator = {
return sql;
},
getPrimaryKeyConstraint(table, attributeName) {

This comment has been minimized.

@sushantdhiman

sushantdhiman Jan 10, 2017

Member

This method only generates SQL, lets call it getPrimaryKeyConstraintQuery

@@ -680,6 +680,25 @@ var QueryGenerator = {
return sql;
},
getPrimaryKeyConstraint(table, attributeName) {
const tableName = wrapSingleQuote(table.tableName || table);
const sql = [

This comment has been minimized.

@sushantdhiman

sushantdhiman Jan 10, 2017

Member

You can directly return query without using sql variable :)

This comment has been minimized.

@harshithkashyap

harshithkashyap Jan 10, 2017

Member

@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.

This comment has been minimized.

@sushantdhiman

sushantdhiman Jan 10, 2017

Member

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

This comment has been minimized.

@harshithkashyap

harshithkashyap Jan 10, 2017

Member

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

@@ -638,6 +638,20 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
expect(table).to.not.have.property('manager');
});
});
it('Should be able to remove a column with primaryKey', function () {

This comment has been minimized.

@sushantdhiman

sushantdhiman Jan 10, 2017

Member

Should => should

@@ -692,6 +706,20 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
expect(table).to.not.have.property('lastName');
});
});
it('Should be able to remove a column with primaryKey', function () {

This comment has been minimized.

@sushantdhiman

sushantdhiman Jan 10, 2017

Member

Should => should

harshithkashyap added some commits Jan 10, 2017

@sushantdhiman sushantdhiman merged commit 37e8402 into sequelize:master Jan 11, 2017

4 checks passed

codecov/patch 100% of diff hit (target 94.81%)
Details
codecov/project 94.82% (+<.01%) compared to 54556cc
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@harshithkashyap harshithkashyap deleted the harshithkashyap:mssql-drop-primarykey-constraint branch Jan 12, 2017

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