From 3198b7c2192cc14c42ec3ea705cbedd3a5410ea6 Mon Sep 17 00:00:00 2001 From: Dave Shrewsberry Date: Thu, 1 Aug 2024 17:23:39 -0400 Subject: [PATCH] more tracing --- migrator/migrator.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 678cf566..079754e1 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -710,6 +710,7 @@ func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name st for _, rel := range stmt.Schema.Relationships.Relations { if constraint := rel.ParseConstraint(); constraint != nil && constraint.Name == name { + fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for relation 0 %q", constraint)) return constraint, getTable(rel) } } @@ -718,6 +719,7 @@ func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name st for k := range checkConstraints { if checkConstraints[k].Field == field { v := checkConstraints[k] + fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for check %q", &v)) return &v, stmt.Table } } @@ -725,12 +727,14 @@ func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name st for k := range uniqueConstraints { if uniqueConstraints[k].Field == field { v := uniqueConstraints[k] + fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for unique %q", &v)) return &v, stmt.Table } } for _, rel := range stmt.Schema.Relationships.Relations { if constraint := rel.ParseConstraint(); constraint != nil && rel.Field == field { + fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for relation %q", constraint)) return constraint, getTable(rel) } } @@ -757,10 +761,10 @@ func (m Migrator) CreateConstraint(value interface{}, name string) error { // DropConstraint drop constraint func (m Migrator) DropConstraint(value interface{}, name string) error { + fmt.Println(fmt.Sprintf("SHREWS --In Drop %q", name)) return m.RunWithValue(value, func(stmt *gorm.Statement) error { if !m.HasConstraint(value, name) { - constraint, _ := m.GuessConstraintInterfaceAndTable(stmt, name) - return errors.New(fmt.Sprintf("Can't find constraint for %q, with guessed name %q", name, constraint)) + return nil } constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) if constraint != nil {