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

add UniqueIndex attribute to Field strucrt(The check error is not caused by my code) #5341

Closed
wants to merge 2 commits into from

Conversation

piyongcai
Copy link
Contributor

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

What did this pull request do?

add UniqueIndex attribute to Field strucrt

in some case,

  1. defind a struct field and set uniqueIndex tag ony. and call AutoMigrate
  2. in some case, you must call AutoMigrage more than once. (eg, restart your app or change struct), the db return unique = true, but field struct return unique = false.
  3. it will be call AlterColumn. in some time(eg: partition table), it will be failure.

in schema/field.go
1.Add UniqueIndex field to Field's struct。
4.Resolve UniqueIndex value from StructField.

in migrator/migrator.go -> MigrateColumn
1.check unique, Check for the uniqueIndex and unique simultaneously

User Case Description

type Order struct{
   ID int                     `gorm:"uniqueIndex:uk@order"`
   BizTime time.Time `gorm:"uniqueIndex:uk@order"`  // it's partition field.
}

// db init
// init PartitionTable 
//..... first
if err := db.AutoMigrate(&Order{}); err != nil{
   painc(err)
}

//... db.AutoMigrate Again. 
if err := db.AutoMigrate(&Order{}); err != nil{
   painc(err)  // it will be painc.  becouse alter Partition Field BizTime
}

piyongcai added 2 commits May 16, 2022 10:22
1.Add UniqueIndex field to Field's struct。
2.Resolve UniqueIndex value from StructField.

in migrator/migrator.go -> MigrateColumn
1.check unique, Check for the uniqueIndex and unique simultaneously
@piyongcai piyongcai changed the title add UniqueIndex attribute to Field strucrt add UniqueIndex attribute to Field strucrt(Check Error isn't my code) May 16, 2022
@piyongcai piyongcai changed the title add UniqueIndex attribute to Field strucrt(Check Error isn't my code) add UniqueIndex attribute to Field strucrt(The check error is not caused by my code) May 16, 2022
@jinzhu
Copy link
Member

jinzhu commented May 30, 2022

Hi @piyongcai

Seems CI failed for this PR.

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.

标签 uniqueIndex 在解析唯一性时未被判断,查看源代码发现仅判断了UNIQUE
2 participants