87 lines
2.1 KiB
Python
87 lines
2.1 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 data_attr_index():
|
|
await crud.data_attr.create_index(db)
|
|
|
|
|
|
async def event_mana():
|
|
await crud.event_mana.create_index(db)
|
|
|
|
|
|
async def api_list_index():
|
|
await crud.api_list.create_index(db)
|
|
|
|
async def role_index():
|
|
await crud.role.create_index(db)
|
|
|
|
|
|
async def authority_init():
|
|
await crud.authority.create_index(db)
|
|
await crud.authority.create(db, 'p', '*', '*', '/docs', '*')
|
|
await crud.authority.create(db, 'p', '*', '*', '/openapi.json', '*')
|
|
await crud.authority.create(db, 'p', '*', '*', '/api/v1/user/login', '*')
|
|
await crud.authority.create(db, 'p', '*', '*', '/docs', '*')
|
|
await crud.authority.create(db, 'p', '*', '*', '/api/v1/project/', '*')
|
|
|
|
|
|
async def main():
|
|
# await create_superuser()
|
|
# await project_index()
|
|
# await folder_index()
|
|
# await space_index()
|
|
# await dashboard_index()
|
|
# await report_index()
|
|
# await authority_init()
|
|
# await data_attr_index()
|
|
# await event_mana()
|
|
await api_list_index()
|
|
await role_index()
|
|
|
|
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(main())
|