Skip to content

Commit 4efd3e1

Browse files
committed
Upgrade gorm to v1.20.12 & Refactor HasConstraint
1 parent 813b119 commit 4efd3e1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ go 1.14
44

55
require (
66
github.com/jackc/pgx/v4 v4.10.1
7-
gorm.io/gorm v1.20.11
7+
gorm.io/gorm v1.20.12
88
)

migrator.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,16 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
266266
func (m Migrator) HasConstraint(value interface{}, name string) bool {
267267
var count int64
268268
m.RunWithValue(value, func(stmt *gorm.Statement) error {
269+
constraint, chk, table := m.GuessConstraintAndTable(stmt, name)
270+
if constraint != nil {
271+
name = constraint.Name
272+
} else if chk != nil {
273+
name = chk.Name
274+
}
275+
269276
return m.DB.Raw(
270277
"SELECT count(*) FROM INFORMATION_SCHEMA.table_constraints WHERE table_schema = ? AND table_name = ? AND constraint_name = ?",
271-
m.CurrentSchema(stmt), stmt.Table, name,
278+
m.CurrentSchema(stmt), table, name,
272279
).Row().Scan(&count)
273280
})
274281

0 commit comments

Comments
 (0)