Fix DB issues
This commit is contained in:
parent
21cc875cc0
commit
16abc95b4f
@ -2,10 +2,10 @@ package fic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// db stores the connection to the database
|
// db stores the connection to the database
|
||||||
@ -44,7 +44,7 @@ func DSNGenerator() string {
|
|||||||
|
|
||||||
// DBInit establishes the connection to the database
|
// DBInit establishes the connection to the database
|
||||||
func DBInit(dsn string) (err error) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,16 +409,15 @@ CREATE TABLE IF NOT EXISTS claims(
|
|||||||
CREATE TABLE IF NOT EXISTS claim_descriptions(
|
CREATE TABLE IF NOT EXISTS claim_descriptions(
|
||||||
id_description INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_description INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
id_claim INTEGER NOT NULL,
|
id_claim INTEGER NOT NULL,
|
||||||
id_assignee INTEGER NOT NULL,
|
id_assignee INTEGER,
|
||||||
date TIMESTAMP NOT NULL,
|
date TIMESTAMP NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
publish BOOLEAN NOT NULL DEFAULT 0,
|
publish BOOLEAN NOT NULL DEFAULT 0,
|
||||||
FOREIGN KEY(id_assignee) REFERENCES claim_assignees(id_assignee),
|
|
||||||
FOREIGN KEY(id_claim) REFERENCES claims(id_claim)
|
FOREIGN KEY(id_claim) REFERENCES claims(id_claim)
|
||||||
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return err
|
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 {
|
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
|
return err
|
||||||
|
@ -235,7 +235,9 @@ func (e Exercice) Delete() (int64, error) {
|
|||||||
func (e Exercice) DeleteCascade() (int64, error) {
|
func (e Exercice) DeleteCascade() (int64, error) {
|
||||||
if _, err := DBExec("UPDATE exercices SET id_depend = NULL WHERE id_depend = ?", e.Id); err != nil {
|
if _, err := DBExec("UPDATE exercices SET id_depend = NULL WHERE id_depend = ?", e.Id); err != nil {
|
||||||
return 0, err
|
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
|
return 0, err
|
||||||
} else if _, err := DBExec("DELETE FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
} else if _, err := DBExec("DELETE FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
Loading…
Reference in New Issue
Block a user