Add categories to sort/filter works/surveys
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b88d284859
commit
4c76dd9728
17 changed files with 586 additions and 25 deletions
20
db.go
20
db.go
|
@ -93,6 +93,7 @@ CREATE TABLE IF NOT EXISTS user_keys(
|
|||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS surveys(
|
||||
id_survey INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
id_category INTEGER NOT NULL,
|
||||
title VARCHAR(255),
|
||||
promo MEDIUMINT NOT NULL,
|
||||
grp VARCHAR(255) NOT NULL,
|
||||
|
@ -100,7 +101,8 @@ CREATE TABLE IF NOT EXISTS surveys(
|
|||
direct INTEGER DEFAULT NULL,
|
||||
corrected BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
start_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
end_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
end_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(id_category) REFERENCES categories(id_category)
|
||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||
`); err != nil {
|
||||
return err
|
||||
|
@ -200,6 +202,7 @@ CREATE TABLE IF NOT EXISTS user_need_help(
|
|||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS works(
|
||||
id_work INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
id_category INTEGER NOT NULL,
|
||||
title VARCHAR(255),
|
||||
promo MEDIUMINT NOT NULL,
|
||||
grp VARCHAR(255) NOT NULL,
|
||||
|
@ -209,7 +212,8 @@ CREATE TABLE IF NOT EXISTS works(
|
|||
submission_URL VARCHAR(255) NULL,
|
||||
corrected BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
start_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
end_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
end_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY(id_category) REFERENCES categories(id_category)
|
||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||
`); err != nil {
|
||||
return err
|
||||
|
@ -241,6 +245,16 @@ CREATE TABLE IF NOT EXISTS user_work_repositories(
|
|||
FOREIGN KEY(id_work) REFERENCES works(id_work),
|
||||
UNIQUE one_repo_per_work (id_user, id_work)
|
||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS categories(
|
||||
id_category INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
label VARCHAR(255) NOT NULL,
|
||||
promo MEDIUMINT NOT NULL,
|
||||
expand BOOLEAN NOT NULL DEFAULT FALSE
|
||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -250,7 +264,7 @@ CREATE VIEW IF NOT EXISTS student_scores AS SELECT T.id_user, T.id_survey, Q.id_
|
|||
return err
|
||||
}
|
||||
if _, err := db.Exec(`
|
||||
CREATE VIEW IF NOT EXISTS all_works AS SELECT "work" AS kind, id_work AS id, title, promo, grp, shown, NULL AS direct, submission_url, corrected, start_availability, end_availability FROM works UNION SELECT "survey" AS kind, id_survey AS id, title, promo, grp, shown, direct, NULL AS submission_url, corrected, start_availability, end_availability FROM surveys;
|
||||
CREATE VIEW IF NOT EXISTS all_works AS SELECT "work" AS kind, id_work AS id, id_category, title, promo, grp, shown, NULL AS direct, submission_url, corrected, start_availability, end_availability FROM works UNION SELECT "survey" AS kind, id_survey AS id, id_category, title, promo, grp, shown, direct, NULL AS submission_url, corrected, start_availability, end_availability FROM surveys;
|
||||
`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Reference in a new issue