test: pgsql migrate unique index (#6028)

This commit is contained in:
Cr 2023-02-18 09:21:07 +08:00 committed by GitHub
parent e66a059b82
commit 04cbd956eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -259,6 +259,7 @@ func TestMigrateWithUniqueIndex(t *testing.T) {
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) {