diff --git a/libfic/db.go b/libfic/db.go index 407dd5b6..8a66087d 100644 --- a/libfic/db.go +++ b/libfic/db.go @@ -2,10 +2,10 @@ package fic import ( "database/sql" + _ "github.com/go-sql-driver/mysql" "log" "os" "time" - _ "github.com/go-sql-driver/mysql" ) // db stores the connection to the database @@ -44,7 +44,7 @@ func DSNGenerator() string { // DBInit establishes the connection to the database func DBInit(dsn string) (err error) { - if db, err = sql.Open("mysql", dsn + "?parseTime=true&foreign_key_checks=1"); err != nil { + if db, err = sql.Open("mysql", dsn+"?parseTime=true&foreign_key_checks=1"); err != nil { return } @@ -409,16 +409,15 @@ CREATE TABLE IF NOT EXISTS claims( CREATE TABLE IF NOT EXISTS claim_descriptions( id_description INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, id_claim INTEGER NOT NULL, - id_assignee INTEGER NOT NULL, + id_assignee INTEGER, date TIMESTAMP NOT NULL, content TEXT NOT NULL, publish BOOLEAN NOT NULL DEFAULT 0, - FOREIGN KEY(id_assignee) REFERENCES claim_assignees(id_assignee), FOREIGN KEY(id_claim) REFERENCES claims(id_claim) ) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; `); err != nil { return err -} + } if _, err := db.Exec("CREATE OR REPLACE VIEW exercice_distinct_tries AS SELECT id_exercice, id_team, MAX(time) AS time, cksum, nbdiff FROM exercice_tries GROUP BY id_team, id_exercice, cksum;"); err != nil { return err diff --git a/libfic/exercice.go b/libfic/exercice.go index 26894368..a428ca38 100644 --- a/libfic/exercice.go +++ b/libfic/exercice.go @@ -235,7 +235,9 @@ func (e Exercice) Delete() (int64, error) { func (e Exercice) DeleteCascade() (int64, error) { if _, err := DBExec("UPDATE exercices SET id_depend = NULL WHERE id_depend = ?", e.Id); err != nil { return 0, err - } else if _, err := DBExec("DELETE FROM exercice_files_deps WHERE id_file IN (SELECT id_file FROM exercice_files WHERE id_exercice = ?)", e.Id); err != nil { + } else if _, err := DBExec("DELETE FROM exercice_files_okey_deps WHERE id_file IN (SELECT id_file FROM exercice_files WHERE id_exercice = ?)", e.Id); err != nil { + return 0, err + } else if _, err := DBExec("DELETE FROM exercice_files_omcq_deps WHERE id_file IN (SELECT id_file FROM exercice_files WHERE id_exercice = ?)", e.Id); err != nil { return 0, err } else if _, err := DBExec("DELETE FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil { return 0, err