-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
schemadiff: Fix handling of primary key #11059
schemadiff: Fix handling of primary key #11059
Conversation
This fixes the handling of primary key options. When dropping a primary key, we should use `drop primary key` and not use the name. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
dropKey := &sqlparser.DropKey{} | ||
if strings.EqualFold(dropKey.Name.String(), "PRIMARY") { | ||
if strings.EqualFold(info.Type, sqlparser.PrimaryKeyTypeStr) { |
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.
This wasn't even checking anything at all. It checked the name of dropKey
but that was just initialized to a new struct so this check would never be true at all. By passing in the more details from info
we can check the actual type.
@@ -1631,7 +1631,15 @@ func (c *CreateTableEntity) apply(diff *AlterTableEntityDiff) error { | |||
// we expect the named key to be found | |||
found := false | |||
switch opt.Type { | |||
case sqlparser.NormalKeyType, sqlparser.PrimaryKeyType: | |||
case sqlparser.PrimaryKeyType: |
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.
This should be handled separately since we want to check the type in this case, not the name. There's only one primary key anyway so we need to find that.
The statement |
Ah ok, I had no idea tbh that that worked at all 🤦. Never seen the syntax, always see If we want to keep the existing though, we still have an issue I think since #11059 (comment) seems like it would be wrong still since |
Yeah, so the name of the |
This fixes the handling of primary key options. When dropping a primary key, we should use `drop primary key` and not use the name. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com> Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com> Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
This fixes the handling of primary key options. When dropping a primary key, we should use
drop primary key
and not use the name.Related Issue(s)
#10203
Checklist