This commit is contained in:
parent
1146dd6773
commit
6ff528d9b0
|
|
@ -9,5 +9,5 @@ COPY src/ .
|
|||
# 暴露端口
|
||||
EXPOSE 8000
|
||||
|
||||
# 启动命令:先执行数据库迁移,再启动 uvicorn
|
||||
CMD ["sh", "-c", "alembic upgrade head 2>/dev/null || true && uvicorn main:app --host 0.0.0.0 --port 8000"]
|
||||
# 启动命令:先执行数据库迁移,再创建管理员用户,最后启动 uvicorn
|
||||
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"]
|
||||
|
|
@ -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';
|
||||
Loading…
Reference in New Issue