db: add constraints to avoid multiple records of unique values

This commit is contained in:
nemunaire 2017-01-29 18:12:21 +01:00
parent a43c5fbd55
commit acfd7a74ae

View file

@ -128,6 +128,7 @@ CREATE TABLE IF NOT EXISTS exercice_solved(
id_team INTEGER NOT NULL, id_team INTEGER NOT NULL,
time TIMESTAMP NOT NULL, time TIMESTAMP NOT NULL,
coefficient FLOAT NOT NULL DEFAULT 1.0, 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_exercice) REFERENCES exercices(id_exercice),
FOREIGN KEY(id_team) REFERENCES teams(id_team) FOREIGN KEY(id_team) REFERENCES teams(id_team)
); );
@ -150,12 +151,16 @@ CREATE TABLE IF NOT EXISTS team_hints(
id_team INTEGER, id_team INTEGER,
id_hint INTEGER, id_hint INTEGER,
time TIMESTAMP NOT NULL, time TIMESTAMP NOT NULL,
CONSTRAINT uc_displayed UNIQUE (id_team,id_hint),
FOREIGN KEY(id_hint) REFERENCES exercice_hints(id_hint), FOREIGN KEY(id_hint) REFERENCES exercice_hints(id_hint),
FOREIGN KEY(id_team) REFERENCES teams(id_team) FOREIGN KEY(id_team) REFERENCES teams(id_team)
); );
`); err != nil { `); err != nil {
return err return err
} }
if _, err := db.Exec("SET FOREIGN_KEY_CHECKS = 1;"); err != nil {
return err
}
return nil return nil
} }