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

Full OldTable on AlterTableOperation, further comment support #16981

Merged
merged 1 commit into from
Aug 9, 2019

Conversation

roji
Copy link
Member

@roji roji commented Aug 6, 2019

Changed AlterTableOperation.OldTable from Annotatable to TableOperation,
and did various fixes throughout to support comment alteration on tables.

Some comment fixes and refactoring.

Fixes #16819
Fixes #16798

  • The extended property functions (e.g. sp_addextendedproperty) don't accept NULL for schema - it must always be passed. Am defaulting to the model default and after that to dbo, hopefully that's right.
  • Trying to call sp_addextendedproperty or sp_dropextendedproperty twice results in an error (property is already defined), meaning that this comment implementation isn't idempotent. Does it need to be?

@roji roji requested a review from bricelam August 6, 2019 10:48
@roji roji force-pushed the AlterTableComment branch from d51a081 to 0b8cf69 Compare August 6, 2019 11:41
return;
}

schema ??= model?.GetDefaultSchema() ?? DefaultSchema;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably generate SCHEMA_NAME() in the SQL instead of relying on hard-coding dbo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently can't pass function calls to SQL Server stored procedures, need to define a variable instead?

😖

Declared a variable, which forces us to think about variable scope etc. - take a look at the second commit.

On the way found another bug where we weren't generating column comments in migration C# code for CreateTable...

@roji roji force-pushed the AlterTableComment branch 3 times, most recently from ec2f71b to f532505 Compare August 9, 2019 17:59
Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

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

:shipit: (After addressing comments)

builder.Append("SET @schema = SCHEMA_NAME()")
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
}
schema = "@schema";
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a variable at all? Can't we just inline SCHEMA_NAME()?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean inline SCHEMA_NAME() into the stored procedure EXEC call? Apparently that simply isn't supported, only literals and variables (e.g. https://www.sqlservercentral.com/forums/topic/using-functions-as-parameters-in-stored-procedure-calls).

I definitely don't like that extra T-SQL variable, e.g. it forces us to distinguish first GenerateComment call (which declares and sets it) and the others (which don't, since it's also not possible to re-declare or un-declare a variable).

Will hold off on merging this in case you have some better SQL Server trick or something - otherwise let me know and I'll merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Doh, just saw your comment above about this too)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any better ideas

Changed AlterTableOperation.OldTable from Annotatable to TableOperation,
and did various fixes throughout to support comment alteration on tables.

Some comment fixes and refactoring.

Fixes #16819
Fixes #16798
@roji roji force-pushed the AlterTableComment branch from f532505 to 3148cd0 Compare August 9, 2019 18:58
@roji roji merged commit 841963d into release/3.0 Aug 9, 2019
@ghost ghost deleted the AlterTableComment branch August 9, 2019 21:48
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.

Cleanup or back-out support for column/table comments AlterTableOperation doesn't have a full OldTable
2 participants