From 43d14484671eaa97deacf191e177485e971554fe Mon Sep 17 00:00:00 2001 From: Zagarazhi Date: Fri, 16 Aug 2024 10:29:06 +0400 Subject: [PATCH] add fk constraint param --- utils/gorm.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/gorm.go b/utils/gorm.go index 682cca9..8f8fdf7 100644 --- a/utils/gorm.go +++ b/utils/gorm.go @@ -9,7 +9,7 @@ import ( "gorm.io/gorm/schema" ) -func NewGormConn(db, dbschema, user, pswd, host string, port int) (conn *gorm.DB, err error) { +func NewGormConn(db, dbschema, user, pswd, host string, port int, disableForeignKeyConstraintWhenMigrating bool) (conn *gorm.DB, err error) { if len(dbschema) == 0 { dbschema = "public" @@ -22,6 +22,7 @@ func NewGormConn(db, dbschema, user, pswd, host string, port int) (conn *gorm.DB TablePrefix: fmt.Sprintf("%s.", dbschema), SingularTable: false, }, + DisableForeignKeyConstraintWhenMigrating: disableForeignKeyConstraintWhenMigrating, }) if err != nil { @@ -43,4 +44,4 @@ func CloseGormConn(conn *gorm.DB) error { } return nil -} \ No newline at end of file +}