init
This commit is contained in:
1 parent
c7fccf99c7
commit
8471f368eb
33 files changed
+444
-2095
No files matched your search
+20
-11
@@ -29,17 +29,27 @@ async def seed_workflows():
|
||||
|
||||
|
||||
async def seed_data():
|
||||
"""Create default admin user from environment config."""
|
||||
"""Create default users with different roles."""
|
||||
from app.core.security import hash_password
|
||||
|
||||
default_users = [
|
||||
{"username": "admin", "display_name": "超级管理员", "role": "admin", "password": "admin123"},
|
||||
{"username": "dba", "display_name": "张三", "role": "dba", "password": "admin123"},
|
||||
{"username": "auditor", "display_name": "老六", "role": "auditor", "password": "admin123"},
|
||||
{"username": "developer", "display_name": "路人甲", "role": "developer", "password": "admin123"},
|
||||
]
|
||||
|
||||
async with async_session() as db:
|
||||
result = await db.execute(select(User).where(User.username == settings.ADMIN_USERNAME))
|
||||
if not result.scalar_one_or_none():
|
||||
db.add(User(
|
||||
username=settings.ADMIN_USERNAME,
|
||||
display_name="管理员",
|
||||
role="admin",
|
||||
hashed_password=hash_password(settings.ADMIN_PASSWORD),
|
||||
))
|
||||
await db.commit()
|
||||
for u in default_users:
|
||||
result = await db.execute(select(User).where(User.username == u["username"]))
|
||||
if not result.scalar_one_or_none():
|
||||
db.add(User(
|
||||
username=u["username"],
|
||||
display_name=u["display_name"],
|
||||
role=u["role"],
|
||||
hashed_password=hash_password(u["password"]),
|
||||
))
|
||||
await db.commit()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -62,7 +72,6 @@ async def lifespan(app: FastAPI):
|
||||
import app.models.notification_template # noqa
|
||||
import app.models.scheduled_task # noqa
|
||||
import app.models.schema_revision # noqa
|
||||
import app.models.slow_log # noqa
|
||||
import app.models.query_history # noqa
|
||||
|
||||
await init_db()
|
||||
|
||||
Reference in new issue
Block a user