db: add constraints to avoid multiple records of unique values
This commit is contained in:
parent
4793d0de4e
commit
1a8e7066c3
|
@ -128,6 +128,7 @@ CREATE TABLE IF NOT EXISTS exercice_solved(
|
|||
id_team INTEGER NOT NULL,
|
||||
time TIMESTAMP NOT NULL,
|
||||
coefficient FLOAT NOT NULL DEFAULT 1.0,
|
||||
CONSTRAINT uc_solved UNIQUE (id_exercice,id_team),
|
||||
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice),
|
||||
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||
);
|
||||
|
@ -150,12 +151,16 @@ CREATE TABLE IF NOT EXISTS team_hints(
|
|||
id_team INTEGER,
|
||||
id_hint INTEGER,
|
||||
time TIMESTAMP NOT NULL,
|
||||
CONSTRAINT uc_displayed UNIQUE (id_team,id_hint),
|
||||
FOREIGN KEY(id_hint) REFERENCES exercice_hints(id_hint),
|
||||
FOREIGN KEY(id_team) REFERENCES teams(id_team)
|
||||
);
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := db.Exec("SET FOREIGN_KEY_CHECKS = 1;"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue