67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
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.SUPERUSER_NAME)
|
|
if not user:
|
|
user_in = schemas.UserCreate(
|
|
name=settings.SUPERUSER_NAME,
|
|
email=settings.SUPERUSER_EMAIL,
|
|
password=settings.SUPERUSER_PASSWORD,
|
|
nickname=settings.SUPERUSER_NICKNAME,
|
|
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 report_index():
|
|
await crud.report.create_index(db)
|
|
|
|
|
|
async def authority_init():
|
|
await crud.authority.create_index(db)
|
|
await crud.authority.create(db, 'p', 'anonymous', '*', '/docs', '*')
|
|
await crud.authority.create(db, 'p', 'anonymous', '*', '/openapi.json', '*')
|
|
await crud.authority.create(db, 'p', 'anonymous', '*', '/api/v1/user/login', '*')
|
|
await crud.authority.create(db, 'p', 'anonymous', '*', '/docs', '*')
|
|
|
|
|
|
async def main():
|
|
await create_superuser()
|
|
await project_index()
|
|
await folder_index()
|
|
await space_index()
|
|
await dashboard_index()
|
|
await report_index()
|
|
await authority_init()
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(main())
|