Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto migrate tries to delete non-existent unique constraint #7135

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more tracing
dashrews78 committed Aug 1, 2024
commit 3198b7c2192cc14c42ec3ea705cbedd3a5410ea6
8 changes: 6 additions & 2 deletions migrator/migrator.go
Original file line number Diff line number Diff line change
@@ -710,6 +710,7 @@

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))

Check failure on line 713 in migrator/migrator.go

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple) Raw Output: migrator/migrator.go:713:4: S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple) fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for relation 0 %q", constraint)) ^

Check failure on line 713 in migrator/migrator.go

GitHub Actions / sqlite (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / sqlite (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / sqlite (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / postgres (postgres:14, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / sqlserver (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / sqlserver (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / sqlserver (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 713 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint
return constraint, getTable(rel)
}
}
@@ -718,19 +719,22 @@
for k := range checkConstraints {
if checkConstraints[k].Field == field {
v := checkConstraints[k]
fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for check %q", &v))

Check failure on line 722 in migrator/migrator.go

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple) Raw Output: migrator/migrator.go:722:5: S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple) fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for check %q", &v)) ^

Check failure on line 722 in migrator/migrator.go

GitHub Actions / sqlite (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / sqlite (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / sqlite (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / postgres (postgres:14, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / sqlserver (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / sqlserver (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / sqlserver (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint

Check failure on line 722 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.CheckConstraint
return &v, stmt.Table
}
}

for k := range uniqueConstraints {
if uniqueConstraints[k].Field == field {
v := uniqueConstraints[k]
fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for unique %q", &v))

Check failure on line 730 in migrator/migrator.go

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple) Raw Output: migrator/migrator.go:730:5: S1038: should use fmt.Printf instead of fmt.Println(fmt.Sprintf(...)) (but don't forget the newline) (gosimple) fmt.Println(fmt.Sprintf("SHREWS --Out of Guess for unique %q", &v)) ^

Check failure on line 730 in migrator/migrator.go

GitHub Actions / sqlite (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / sqlite (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / sqlite (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / postgres (postgres:14, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / sqlserver (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / sqlserver (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / sqlserver (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint

Check failure on line 730 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg &v of wrong type *gorm.io/gorm/schema.UniqueConstraint
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))

Check failure on line 737 in migrator/migrator.go

GitHub Actions / sqlite (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / sqlite (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / sqlite (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / postgres (postgres:14, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / postgres (postgres:13, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mysql (mysql/mysql-server:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / sqlserver (1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / sqlserver (1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mariadb (mariadb:latest, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / mysql (mysql:5.7, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / sqlserver (1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.22, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.20, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint

Check failure on line 737 in migrator/migrator.go

GitHub Actions / tidb (v6.5.0, 1.21, ubuntu-latest)

fmt.Sprintf format %q has arg constraint of wrong type *gorm.io/gorm/schema.Constraint
return constraint, getTable(rel)
}
}
@@ -757,10 +761,10 @@

// 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 {