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

Removed UNIQUE in SQL when the field is already unique #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shanehou
Copy link

@shanehou shanehou commented May 14, 2023

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Fixed go-gorm/gorm#6224.

Removed UNIQUE in SQL when the field is already unique.

User Case Description

Running AutoMigrating multiple times on fields with uniqueIndex tag will not creating multiple unique indexes.

@shanehou shanehou changed the title Removed in SQL when the field is already unique Removed UNIQUE in SQL when the field is already unique May 14, 2023
Copy link
Member

@a631807682 a631807682 left a comment

Choose a reason for hiding this comment

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

This is a breaking change and will make the following code invalid

// from
Name string `gorm:"not null;default:"`
// to
Name string `gorm:"unique;not null;default:"`

We need to distinguish between UNIQUE and UNIQUE INDEX, because they also need to be compared and migrated

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.

Unnecessarily unique indexes created when running AutoMigrate
2 participants