From f044ab8ed74df2ff5cf28bb1cbedb0bafd0cf2b5 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 22 Oct 2022 06:34:12 +0800 Subject: [PATCH] chore(web): update definition of `groups_assignments` --- db/app_uoj233.sql | 5 ++--- web/app/libs/uoj-query-lib.php | 4 ++-- web/app/upgrade/8_group_v2/down.sql | 2 ++ web/app/upgrade/8_group_v2/up.sql | 2 ++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index 3ae2d3a..c33a8ce 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -455,11 +455,10 @@ CREATE TABLE `groups` ( /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `groups_assignments` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `list_id` int(11) NOT NULL, `group_id` int(11) NOT NULL, + `list_id` int(11) NOT NULL, `end_time` datetime NOT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`group_id`, `list_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/web/app/libs/uoj-query-lib.php b/web/app/libs/uoj-query-lib.php index e6d69ad..330a348 100644 --- a/web/app/libs/uoj-query-lib.php +++ b/web/app/libs/uoj-query-lib.php @@ -146,10 +146,10 @@ function queryGroupCurrentAC($group_id) { return DB::selectAll("select a.problem_id as problem_id, a.submitter as submitter, a.submission_id as submission_id, b.submit_time as submit_time, d.title as problem_title, b.submit_time as submit_time, e.realname as realname from best_ac_submissions a inner join submissions b on (a.submission_id = b.id) inner join groups_users c on (a.submitter = c.username and c.group_id = $group_id) inner join problems d on (a.problem_id = d.id and d.is_hidden = 0) inner join user_info e on (a.submitter = e.username) where b.submit_time > addtime(now(), '-360:00:00') order by b.submit_time desc limit 10", MYSQLI_ASSOC); } function queryGroupAssignments($group_id) { - return DB::selectAll("select a.id as id, a.list_id as list_id, a.end_time as end_time, b.title from groups_assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id order by a.end_time asc", MYSQLI_ASSOC); + return DB::selectAll("select a.list_id as list_id, a.end_time as end_time, b.title from groups_assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id order by a.end_time asc", MYSQLI_ASSOC); } function queryGroupActiveAssignments($group_id) { - return DB::selectAll("select a.id as id, a.group_id as group_id, a.list_id as list_id, a.end_time as end_time, b.title from groups_assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id and a.end_time >= addtime(now(), '-168:00:00') order by a.end_time asc", MYSQLI_ASSOC); + return DB::selectAll("select a.group_id as group_id, a.list_id as list_id, a.end_time as end_time, b.title from groups_assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id and a.end_time >= addtime(now(), '-168:00:00') order by a.end_time asc", MYSQLI_ASSOC); } function queryAssignmentByGroupListID($group_id, $list_id) { return DB::selectFirst("select * from groups_assignments where list_id='$list_id' and group_id='$group_id'", MYSQLI_ASSOC); diff --git a/web/app/upgrade/8_group_v2/down.sql b/web/app/upgrade/8_group_v2/down.sql index 8008d9d..b77c2f6 100644 --- a/web/app/upgrade/8_group_v2/down.sql +++ b/web/app/upgrade/8_group_v2/down.sql @@ -1,4 +1,6 @@ RENAME TABLE groups_assignments TO assignments; +ALTER TABLE `assignments` ADD COLUMN `id` int(11) NOT NULL AUTO_INCREMENT; +ALTER TABLE `assignments` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`); ALTER TABLE `assignments` ADD COLUMN `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP; ALTER TABLE `assignments` CHANGE COLUMN `end_time` `deadline` datetime NOT NULL; ALTER TABLE `countdowns` CHANGE COLUMN `end_time` `endtime` datetime NOT NULL; diff --git a/web/app/upgrade/8_group_v2/up.sql b/web/app/upgrade/8_group_v2/up.sql index 347d0b1..8dea4cc 100644 --- a/web/app/upgrade/8_group_v2/up.sql +++ b/web/app/upgrade/8_group_v2/up.sql @@ -1,4 +1,6 @@ RENAME TABLE assignments TO groups_assignments; +ALTER TABLE `assignments` DROP PRIMARY KEY, ADD PRIMARY KEY (`group_id`, `list_id`); +ALTER TABLE `assignments` DROP COLUMN `id`; ALTER TABLE `groups_assignments` DROP COLUMN `create_time`; ALTER TABLE `groups_assignments` CHANGE COLUMN `deadline` `end_time` datetime NOT NULL; ALTER TABLE `countdowns` CHANGE COLUMN `endtime` `end_time` datetime NOT NULL;