-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 #6381
Comments
Let me do the distinguish in gorm (I touched the checkbox by mistake |
Is the index created repeatedly because of this? (#5715 & #6224) Here's a playground I created: go-gorm/playground#609 |
Here is a mysql example type Test struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"type:varchar(10);uniqueIndex"`
}
type Test1 struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"type:varchar(20);uniqueIndex"`
}
func TestGORM(t *testing.T) {
DB.Migrator().DropTable(&Test{})
DB.AutoMigrate(&Test{})
DB.Table("tests").AutoMigrate(&Test1{})
indexs, err := DB.Migrator().GetIndexes(&Test{})
if err != nil {
t.Fatal(err)
}
if len(indexs) != 2 { // pk and unique index
t.Fatalf("should have one index, but got %v", len(indexs))
}
}
We also need to pay attention to such scenarios type Test2 struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"type:varchar(20);uniqueIndex:uniq_name_code;index"` // index and uniqueIndex
Code string `gorm:"type:varchar(20);uniqueIndex:uniq_name_code"`
} |
There is another situation here. Since unique and unique index cannot be distinguished, |
I will continue to work on mysql and postgres |
When all the drivers are completed and tested, So continue to do sqlite and sqlserver... |
Thank you for your contribution |
any update on this? I can confirm from black-06's branch and the postgres driver it works for me, in the meantime we can't upgrade gorm beyond 1.24.2 due to this issue (but would like to do so in order to get some nested join fixes) |
I am pleased to announce that we have completed the work. But note that gorm v1.25.7 should work with (or higher version) sqlite v1.5.5, mysql v1.5.4, postgres v1.5.6, sqlserver v1.5.3 otherwise there may be some unexpected problems. Similarly, these (or higher) versions of drivers require gorm v1.25.7 (or higher) |
Describe the feature
Distinguish between unique index and index to better support them.
Motivation
Because we can't distinguish them at present, it causes such as #6224 (comment), and column will not be able to set unique index and index at the same time
The following tasks are open
If anyone is interested in the above tasks, please leave a message in the comments.
Related Issues
related issues:
#6224
#5401
#5715
#5681
#6378
#6407
related pull request:
#5341
The text was updated successfully, but these errors were encountered: