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

No-op bad alter table auto increment #1930

Merged
merged 10 commits into from Jul 21, 2021
Merged

No-op bad alter table auto increment #1930

merged 10 commits into from Jul 21, 2021

Conversation

VinaiRachakonda
Copy link
Contributor

@VinaiRachakonda VinaiRachakonda commented Jul 19, 2021

Pr does 2 things

  1. Fix panic on linked issue
  2. Actually allow you to modify a column to add an AI

@VinaiRachakonda VinaiRachakonda linked an issue Jul 19, 2021 that may be closed by this pull request
@VinaiRachakonda VinaiRachakonda changed the title fix Nop bad alter table auto increment Jul 19, 2021
// In the case that someone runs an alter table auto increment on a table with no existing auto increment key, nop
if te.autoIncCol.TypeInfo == nil {
return nil
}
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 no-op in the SQL engine, before we get here

Comment on lines 153 to 155
// In the case that the alter table is adding a new auto increment value, then it will return a
// ErrorNoAutoIncrement value. We can ignore that.
if err != nil && !errors.Is(err, doltdb.ErrNoAutoIncrementValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

inspect the old/new schemas and catch the case where auto_increment has been added to a column

Copy link
Contributor

@andy-wm-arthur andy-wm-arthur left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -147,7 +147,7 @@ func updateTableWithModifiedColumn(ctx context.Context, tbl *doltdb.Table, oldSc
return nil, err
}
var autoVal types.Value
if schema.HasAutoIncrement(newSch) {
if schema.HasAutoIncrement(newSch) && schema.HasAutoIncrement(oldSch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks much better, could you add a comment explaining the alter table case? Also, what happens if the AUTO_INCREMENT is removed from the schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new schema would not have auto increment an a nil value would be passed for autoVal

@timsehn
Copy link
Sponsor Contributor

timsehn commented Jul 21, 2021

Change the Title from "Nop" to "No-op" please

@VinaiRachakonda VinaiRachakonda changed the title Nop bad alter table auto increment No-op bad alter table auto increment Jul 21, 2021
@VinaiRachakonda VinaiRachakonda merged commit 3111cc4 into master Jul 21, 2021
@Hydrocharged Hydrocharged deleted the vinai/1856 branch July 30, 2021 18:18
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.

Panic on ALTER TABLE restaurants AUTO_INCREMENT = 2;
3 participants