Skip to content

Correctly map enum values when altering an enum column. #2958

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

Merged
merged 2 commits into from
May 6, 2025

Conversation

nicktobey
Copy link
Contributor

When altering the possible values of an enum column, the mapping between enum strings and their indexes may change. In order to alter the column correctly, we need to map the old indexes onto the new ones.

This PR fixes two bugs in that mapping process:

  • Previously, we were converting the row to the new schema before setting the enums to their new index. This means that if the old row had an index that didn't exist in the new schema, this conversion would fail. By setting the enums to their new index before we convert the row to the new schema, we avoid this problem.
  • Enum indexes are 1-indexed, with the 0 value representing an "invalid" value. One way to get an invalid enum in MySQL is an INSERT IGNORE statement where the provided value for the enum is out of range. Dolt also allows setting the column to 0 directly, although MySQL does not. Previously, we were not able to alter enum columns if they contained a 0 value, but now we can.

Copy link
Contributor

@macneale4 macneale4 left a comment

Choose a reason for hiding this comment

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

LGTM

@nicktobey nicktobey merged commit c5f7d51 into main May 6, 2025
8 checks passed
@nicktobey nicktobey deleted the nicktobey/enum branch May 6, 2025 00:33
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.

2 participants