做了文件结构的调整,新建了service文件夹存放内部服务。添加了git ignore
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from .user import User
|
||||
from .database import init_db
|
||||
|
||||
__all__ = ["User", "init_db"]
|
||||
__all__ = ["User"]
|
||||
|
@@ -1,26 +0,0 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
from .user import Base, User, UserRole
|
||||
from sqlalchemy import select
|
||||
from config import SYSTEM_ADMIN_CONFIG
|
||||
from service.auth import get_password_hash
|
||||
|
||||
async def init_db(engine: AsyncEngine):
|
||||
"""Initialize database"""
|
||||
async with engine.begin() as conn:
|
||||
# Create all tables
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
# Check if system admin exists
|
||||
result = await conn.execute(
|
||||
select(User).where(User.role == UserRole.SYSTEM_ADMIN)
|
||||
)
|
||||
if not result.scalars().first():
|
||||
# Create default system admin
|
||||
admin = User(
|
||||
username=SYSTEM_ADMIN_CONFIG['username'],
|
||||
password=get_password_hash(SYSTEM_ADMIN_CONFIG['password']),
|
||||
role=UserRole.SYSTEM_ADMIN,
|
||||
description=SYSTEM_ADMIN_CONFIG['description']
|
||||
)
|
||||
conn.add(admin)
|
||||
await conn.commit()
|
Reference in New Issue
Block a user