test: pgsql migrate unique index
This commit is contained in:
parent
e1f46eb802
commit
de99171f36
@ -257,9 +257,10 @@ func TestMigrateWithIndexComment(t *testing.T) {
|
|||||||
|
|
||||||
func TestMigrateWithUniqueIndex(t *testing.T) {
|
func TestMigrateWithUniqueIndex(t *testing.T) {
|
||||||
type UserWithUniqueIndex struct {
|
type UserWithUniqueIndex struct {
|
||||||
ID int
|
ID int
|
||||||
Name string `gorm:"size:20;index:idx_name,unique"`
|
Name string `gorm:"size:20;index:idx_name,unique"`
|
||||||
Date time.Time `gorm:"index:idx_name,unique"`
|
Date time.Time `gorm:"index:idx_name,unique"`
|
||||||
|
UName string `gorm:"uniqueIndex;size:255"`
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.Migrator().DropTable(&UserWithUniqueIndex{})
|
DB.Migrator().DropTable(&UserWithUniqueIndex{})
|
||||||
@ -270,6 +271,18 @@ func TestMigrateWithUniqueIndex(t *testing.T) {
|
|||||||
if !DB.Migrator().HasIndex(&UserWithUniqueIndex{}, "idx_name") {
|
if !DB.Migrator().HasIndex(&UserWithUniqueIndex{}, "idx_name") {
|
||||||
t.Errorf("Failed to find created index")
|
t.Errorf("Failed to find created index")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !DB.Migrator().HasIndex(&UserWithUniqueIndex{}, "idx_user_with_unique_indices_u_name") {
|
||||||
|
t.Errorf("Failed to find created index")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.AutoMigrate(&UserWithUniqueIndex{}); err != nil {
|
||||||
|
t.Fatalf("failed to migrate, got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !DB.Migrator().HasIndex(&UserWithUniqueIndex{}, "idx_user_with_unique_indices_u_name") {
|
||||||
|
t.Errorf("Failed to find created index")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrateTable(t *testing.T) {
|
func TestMigrateTable(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user