Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
dashrews78 committed Aug 1, 2024
1 parent e483cd9 commit 38fb45f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ func (m Migrator) CreateConstraint(value interface{}, name string) error {
func (m Migrator) DropConstraint(value interface{}, name string) error {
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
if !m.HasConstraint(value, name) {
return nil
constraint, _ := m.GuessConstraintInterfaceAndTable(stmt, name)
return errors.New(fmt.Sprintf("Can't find constraint for %q, with guessed name %q", name, constraint))

Check failure on line 763 in migrator/migrator.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 S1028: should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) (gosimple) Raw Output: migrator/migrator.go:763:11: S1028: should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) (gosimple) return errors.New(fmt.Sprintf("Can't find constraint for %q, with guessed name %q", name, constraint)) ^
}
constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name)
if constraint != nil {
Expand Down
4 changes: 4 additions & 0 deletions tests/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ func TestMigrateConstraint(t *testing.T) {
DB.Migrator().CreateConstraint(&User{}, name)
}

if !DB.Migrator().HasConstraint(&User{}, name) {
t.Fatalf("failed to create constraint %v", name)
}

if err := DB.Migrator().DropConstraint(&User{}, name); err != nil {
t.Fatalf("failed to drop constraint %v, got error %v", name, err)
}
Expand Down

0 comments on commit 38fb45f

Please sign in to comment.