a-cloud-all/docker/hyf_backend/initdb/02-init-admin-user.sql

41 lines
746 B
MySQL
Raw Normal View History

2026-01-31 15:45:34 +08:00
-- 初始化 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';