diff --git a/docker/hyf_backend/initdb/02-init-admin-user.sql b/docker/hyf_backend/initdb/02-init-admin-user.sql new file mode 100644 index 0000000..c4a08d2 --- /dev/null +++ b/docker/hyf_backend/initdb/02-init-admin-user.sql @@ -0,0 +1,41 @@ +-- 初始化 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'; \ No newline at end of file