chore: add upgrader for #42

This commit is contained in:
Baoshuo Ren 2023-02-15 16:58:53 +08:00
parent 098e488fe3
commit 2cd81ab055
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,8 @@
ALTER TABLE
`user_info`
MODIFY
`usertype` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'student',
MODIFY
`last_login_time` datetime DEFAULT NULL,
MODIFY
`last_visit_time` datetime DEFAULT NULL;

View File

@ -0,0 +1,27 @@
<?php
return function ($type) {
DB::init();
if ($type == 'up') {
$users = DB::selectAll("select * from user_info");
foreach ($users as $user) {
$extra = UOJUser::getExtra($user);
$extra['school'] = $user['school'];
DB::update([
"update user_info",
"set", [
"extra" => json_encode($extra, JSON_UNESCAPED_UNICODE)
],
"where", [
"username" => $user['username']
]
]);
echo "Updated user {$user['username']}. \n";
}
}
};