Django 多个 worker 内存占用 1-2 GB,换成 Bun 单进程后约 25 MB, 同时去掉 Postgres 和 Redis,只剩 Caddy + Bun 两个容器。 - server/:Hono + bun:sqlite + Bun 原生 WebSocket,接口与原 django-ninja 保持兼容;表结构、时间/UUID 存储格式、密码哈希与 Django 一致,旧数据可直接使用 - 评分加权、贝叶斯平滑、成绩册的计算结果与原实现逐位一致(复刻 Python round/sum) - scripts/:Postgres → SQLite 迁移、新建超管、提示词层级标注、重算分数 - 前端:Django Admin 去掉后,用户新建/修改改为页面内弹窗; 非超管的挑战公开按钮置灰 - 权限不足返回 JSON 403(原来是重定向到不存在的登录页) - docker-compose / Caddyfile / dev.sh / CLAUDE.md 更新,删除 AGENTS.md - 服务器切换步骤见 docs/migrate-to-bun.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/**
|
|
* 新建超级管理员,或把已有用户设为超级管理员并重设密码。
|
|
*
|
|
* bun scripts/create-superuser.ts <用户名> <密码>
|
|
*/
|
|
import { get, run, now } from "../src/db"
|
|
import { makePassword } from "../src/auth"
|
|
|
|
const [username, password] = process.argv.slice(2)
|
|
if (!username || !password) {
|
|
console.error("用法:bun scripts/create-superuser.ts <用户名> <密码>")
|
|
process.exit(1)
|
|
}
|
|
|
|
const hash = await makePassword(password)
|
|
const user = get<{ id: number }>(`SELECT id FROM account_user WHERE username = $username`, { username })
|
|
if (user) {
|
|
run(
|
|
`UPDATE account_user SET password = $hash, raw_password = $raw, role = 'super',
|
|
is_superuser = 1, is_staff = 1, is_active = 1 WHERE id = $id`,
|
|
{ hash, raw: password.slice(0, 20), id: user.id },
|
|
)
|
|
run(`DELETE FROM auth_session WHERE user_id = $id`, { id: user.id })
|
|
console.log(`已将 ${username} 设为超级管理员并重设密码`)
|
|
} else {
|
|
run(
|
|
`INSERT INTO account_user
|
|
(password, last_login, is_superuser, username, email, is_staff, is_active, date_joined, role, raw_password, classname)
|
|
VALUES ($hash, NULL, 1, $username, '', 1, 1, $now, 'super', $raw, '')`,
|
|
{ hash, username, now: now(), raw: password.slice(0, 20) },
|
|
)
|
|
console.log(`已创建超级管理员 ${username}`)
|
|
}
|