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

refactor: distinguish between Unique and UniqueIndex #123

Merged
merged 5 commits into from
Feb 6, 2024

Conversation

black-06
Copy link
Contributor

@black-06 black-06 commented Jun 15, 2023

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

What did this pull request do?

See go-gorm/gorm#6381.

based on go-gorm/gorm#6386 and tested

User Case Description

@black-06 black-06 requested a review from a631807682 June 15, 2023 08:57
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.

Depends on gorm's PR, this is a breaking change, releases need to pay attention to the version number.

@black-06
Copy link
Contributor Author

black-06 commented Feb 5, 2024

It still has some problems which I'm fixing

After testing, it works well with go-gorm/gorm#6822

@jinzhu jinzhu merged commit e05761b into go-gorm:master Feb 6, 2024
0 of 3 checks passed
@black-06 black-06 mentioned this pull request Feb 6, 2024
3 tasks
if name := index.Name(); name == constraint || name == field.UniqueIndex {
continue
}
if err := execTx.Migrator().DropIndex(value, index.Name()); err != nil {

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_

_<column_name>

which I changed to

MyColumn int32 gorm:"uniqueIndex"
Gorm retained old index idx_

_<column_name> and created a new unique index <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_

_<column_name> and failed.

Ideally we should have also dropped idx_

_<column_name> once we realised we are creating it.

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

  1. Check if can't create - stop
  2. Drop what we have figured we want to create?

Please let me know.

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.

4 participants