Skip to content

Commit

Permalink
test: pgsql migrate unique index (#6028)
Browse files Browse the repository at this point in the history
  • Loading branch information
a631807682 authored Feb 18, 2023
1 parent e66a059 commit 04cbd95
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ func TestMigrateWithIndexComment(t *testing.T) {

func TestMigrateWithUniqueIndex(t *testing.T) {
type UserWithUniqueIndex struct {
ID int
Name string `gorm:"size:20;index:idx_name,unique"`
Date time.Time `gorm:"index:idx_name,unique"`
ID int
Name string `gorm:"size:20;index:idx_name,unique"`
Date time.Time `gorm:"index:idx_name,unique"`
UName string `gorm:"uniqueIndex;size:255"`
}

DB.Migrator().DropTable(&UserWithUniqueIndex{})
Expand All @@ -269,6 +270,18 @@ func TestMigrateWithUniqueIndex(t *testing.T) {
if !DB.Migrator().HasIndex(&UserWithUniqueIndex{}, "idx_name") {
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) {
Expand Down

0 comments on commit 04cbd95

Please sign in to comment.