fix foreign key constraint not being enforced
This commit is contained in:
parent
a790bc9dd9
commit
e4c9563961
|
@ -37,7 +37,7 @@ func InitSQLite3(path string, schema uint, logger *log.Logger) *CustomDB {
|
||||||
db := CustomDB{logger: logger, schema: schema}
|
db := CustomDB{logger: logger, schema: schema}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
db.connection, err = sql.Open("sqlite3", path)
|
db.connection, err = sql.Open("sqlite3", "file:"+path+"?_foreign_keys=1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
db.logger.Fatalln("Unable to open:", err)
|
db.logger.Fatalln("Unable to open:", err)
|
||||||
}
|
}
|
||||||
|
@ -83,12 +83,7 @@ func (db CustomDB) createSQLite3Tables() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := db.connection.Exec("PRAGMA foreign_keys = ON")
|
_, err := db.connection.Exec("PRAGMA user_version = " + fmt.Sprintf("%d", db.schema))
|
||||||
if err != nil {
|
|
||||||
db.logger.Fatalln("Failed to enable foreign_keys:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = db.connection.Exec("PRAGMA user_version = " + fmt.Sprintf("%d", db.schema))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
db.logger.Fatalln("Failed to set user_version:", err)
|
db.logger.Fatalln("Failed to set user_version:", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue