This commit is contained in:
孙小云 2026-01-31 15:53:44 +08:00
parent 1146dd6773
commit 6ff528d9b0
2 changed files with 2 additions and 43 deletions

View File

@ -9,5 +9,5 @@ COPY src/ .
# 暴露端口 # 暴露端口
EXPOSE 8000 EXPOSE 8000
# 启动命令:先执行数据库迁移,再启动 uvicorn # 启动命令:先执行数据库迁移,再创建管理员用户,最后启动 uvicorn
CMD ["sh", "-c", "alembic upgrade head 2>/dev/null || true && uvicorn main:app --host 0.0.0.0 --port 8000"] CMD ["sh", "-c", "alembic upgrade head 2>/dev/null || true && python scripts/seed_admin.py 2>/dev/null || true && uvicorn main:app --host 0.0.0.0 --port 8000"]

View File

@ -1,41 +0,0 @@
-- 初始化 admin 用户
-- 注意:此脚本假设 users 表已经通过 alembic 迁移创建
-- 插入默认 admin 用户(如果不存在)
INSERT INTO users (
id,
username,
email,
hashed_password,
full_name,
is_active,
avatar_url,
bio,
created_at,
updated_at,
created_by,
updated_by
)
VALUES (
1,
'admin',
'admin@example.com',
'$2b$12$H0YpUrwCCuTISE3D2dQO/uxnBupCf207v1.SFjiAVoCGjkVhK65ou',
'Admin',
true,
NULL,
NULL,
NOW(),
NOW(),
NULL,
NULL
)
ON CONFLICT (id) DO NOTHING;
-- 如果 username 有唯一约束,也可以使用:
-- ON CONFLICT (username) DO NOTHING;
-- 验证插入结果
SELECT id, username, email, full_name, is_active, created_at
FROM users
WHERE username = 'admin';