From 04cbd956ebed5fec1b61a819a3f7494c00d276b3 Mon Sep 17 00:00:00 2001 From: Cr <631807682@qq.com> Date: Sat, 18 Feb 2023 09:21:07 +0800 Subject: [PATCH] test: pgsql migrate unique index (#6028) --- tests/migrate_test.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 8794ccba..5a220ca4 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -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{}) @@ -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) {