1
This commit is contained in:
parent
695a6168ba
commit
3b75cb3999
71
init_db.py
Normal file
71
init_db.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
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 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()
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.run_until_complete(main())
|
Loading…
Reference in New Issue
Block a user