chore: add upgrader for #40

This commit is contained in:
Baoshuo Ren 2023-02-12 21:55:03 +08:00
parent d244f36a25
commit ad0837689a
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 40 additions and 1 deletions

View File

@ -995,7 +995,8 @@ INSERT INTO `upgrades` (`name`, `status`, `updated_at`) VALUES
('21_problem_difficulty', 'up', now()), ('21_problem_difficulty', 'up', now()),
('28_remote_judge', 'up', now()), ('28_remote_judge', 'up', now()),
('31_problem_resources', 'up', now()), ('31_problem_resources', 'up', now()),
('36_decimal_score_range', 'up', now()); ('36_decimal_score_range', 'up', now()),
('40_contest_resources', 'up', now());
/*!40000 ALTER TABLE `upgrades` ENABLE KEYS */; /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;

View File

@ -0,0 +1 @@
ALTER TABLE `contests` MODIFY `extra_config` json NOT NULL;

View File

@ -0,0 +1,37 @@
<?php
return function ($type) {
if ($type == 'up_after_sql') {
DB::init();
$contests = DB::selectAll("select * from contests");
foreach ($contests as $contest) {
$extra_config = json_decode($contest['extra_config'], true);
if (isset($extra_config['links'])) {
$new_links = [];
foreach ($extra_config['links'] as $link) {
if (isset($link['name'])) continue;
$new_links[] = [
'name' => $link[0],
'url' => '/blogs/' . $link[1],
];
}
$extra_config['links'] = $new_links;
}
DB::update([
"update contests",
"set", [
"extra_config" => json_encode($extra_config, JSON_FORCE_OBJECT),
],
"where", [
"id" => $contest['id'],
],
]);
}
}
};