fix foreign key constraint not being enforced

This commit is contained in:
gilex-dev 2023-10-27 13:08:39 +02:00
parent a790bc9dd9
commit e4c9563961
1 changed files with 2 additions and 7 deletions

View File

@ -37,7 +37,7 @@ func InitSQLite3(path string, schema uint, logger *log.Logger) *CustomDB {
db := CustomDB{logger: logger, schema: schema}
var err error
db.connection, err = sql.Open("sqlite3", path)
db.connection, err = sql.Open("sqlite3", "file:"+path+"?_foreign_keys=1")
if err != nil {
db.logger.Fatalln("Unable to open:", err)
}
@ -83,12 +83,7 @@ func (db CustomDB) createSQLite3Tables() error {
}
}
_, err := db.connection.Exec("PRAGMA foreign_keys = ON")
if err != nil {
db.logger.Fatalln("Failed to enable foreign_keys:", err)
}
_, err = db.connection.Exec("PRAGMA user_version = " + fmt.Sprintf("%d", db.schema))
_, err := db.connection.Exec("PRAGMA user_version = " + fmt.Sprintf("%d", db.schema))
if err != nil {
db.logger.Fatalln("Failed to set user_version:", err)
}