admin: add button and route to reset some parts
This commit is contained in:
parent
89eaeef88e
commit
4793d0de4e
4 changed files with 65 additions and 0 deletions
30
libfic/reset.go
Normal file
30
libfic/reset.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package fic
|
||||
|
||||
import ()
|
||||
|
||||
func truncateTable(tables ...string) (error) {
|
||||
if _, err := DBExec("SET FOREIGN_KEY_CHECKS = 0;"); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, table := range tables {
|
||||
if _, err := DBExec("TRUNCATE TABLE " + table + ";"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := DBExec("SET FOREIGN_KEY_CHECKS = 1;"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResetGame() (error) {
|
||||
return truncateTable("team_hints", "key_found", "exercice_solved", "exercice_tries")
|
||||
}
|
||||
|
||||
func ResetExercices() (error) {
|
||||
return truncateTable("team_hints", "exercice_files", "key_found", "exercice_keys", "exercice_solved", "exercice_tries", "exercice_hints", "exercices", "themes")
|
||||
}
|
||||
|
||||
func ResetTeams() (error) {
|
||||
return truncateTable("team_hints", "key_found", "exercice_solved", "exercice_tries", "team_members", "teams")
|
||||
}
|
||||
Reference in a new issue