import crud import schemas from core.config import settings # 创建一个超级用户、、 from db import connect_to_mongo, get_database import asyncio connect_to_mongo() db = get_database() async def create_superuser(): user = await crud.user.get_by_user(db=db, name=settings.FIRST_NAME) if not user: user_in = schemas.UserCreate( name=settings.FIRST_NAME, email=settings.FIRST_EMAIL, password=settings.FIRST_SUPERUSER_PASSWORD, is_superuser=True, ) await crud.user.create(db, user_in) await crud.user.create_index(db) async def project_index(): await crud.project.create_index(db) async def folder_index(): await crud.folder.create_index(db) async def space_index(): await crud.space.create_index(db) async def dashboard_index(): await crud.dashboard.create_index(db) async def main(): await create_superuser() await project_index() await folder_index() await space_index() await dashboard_index() loop = asyncio.get_event_loop() loop.run_until_complete(main())