Skip to content

Commit

Permalink
tests/sqilte: enable FOREIGN_KEYS inside OpenTestConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
glebarez committed Oct 14, 2023
1 parent 6bef318 commit de49b09
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func init() {
}

RunMigrations()
if DB.Dialector.Name() == "sqlite" {
DB.Exec("PRAGMA foreign_keys = ON")
}
}
}

Expand Down Expand Up @@ -89,7 +86,10 @@ func OpenTestConnection(cfg *gorm.Config) (db *gorm.DB, err error) {
db, err = gorm.Open(mysql.Open(dbDSN), cfg)
default:
log.Println("testing sqlite3...")
db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db?_foreign_keys=on")), cfg)
db, err = gorm.Open(sqlite.Open(filepath.Join(os.TempDir(), "gorm.db")), cfg)
if err == nil {
db.Exec("PRAGMA foreign_keys = ON")
}
}

if err != nil {
Expand Down

0 comments on commit de49b09

Please sign in to comment.