-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
refactor: distinguish between Unique and UniqueIndex #123
Conversation
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.
Depends on gorm's PR, this is a breaking change, releases need to pay attention to the version number.
After testing, it works well with go-gorm/gorm#6822 |
if name := index.Name(); name == constraint || name == field.UniqueIndex { | ||
continue | ||
} | ||
if err := execTx.Migrator().DropIndex(value, index.Name()); err != nil { |
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.
I had a column for which I changed from index
to uniqueIndex
MyColumn int32 gorm:"index"
Gorm had created idx_
which I changed to
MyColumn int32 gorm:"uniqueIndex"
Gorm retained old index idx_
<column_name>
After this updatae
gorm.io/driver/mysql v1.5.2 => v1.5.6
gorm.io/gorm v1.25.5 => v1.25.10
It dropped index <column_name> which had unique index and tried to create index with name idx_
Ideally we should have also dropped idx_
As per the text here - https://gorm.io/docs/migration.html 'It WON’T delete unused columns to protect your data.' we should not have done this right '// Clean up redundant unique indexes'
Option could have been
- Check if can't create - stop
- Drop what we have figured we want to create?
Please let me know.
What did this pull request do?
See go-gorm/gorm#6381.
based on go-gorm/gorm#6386 and tested
User Case Description