Skip to content

Commit

Permalink
feat: 优化数据库初始化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Nov 14, 2024
1 parent 47ffb8f commit b079a65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
19 changes: 1 addition & 18 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@

from uvicorn import run as uvicorn_run

from models.debug_project_record import DebugProjectRecord
from models.jianshu.lottery_win_record import LotteryWinRecord
from models.jianshu.user import User
from models.tech_stack import TechStack
from models.tool import Tool
from models import init_db
from utils.config import CONFIG
from utils.db import jianshu_pool, jpep_pool, jtools_pool
from utils.log import logger

logging.getLogger("httpx").setLevel(logging.CRITICAL)
logging.getLogger("httpcore").setLevel(logging.CRITICAL)


async def init_db() -> None:
await jianshu_pool.prepare()
await jpep_pool.prepare()
await jtools_pool.prepare()

await DebugProjectRecord.init()
await LotteryWinRecord.init()
await TechStack.init()
await User.init()
await Tool.init()


if __name__ == "__main__":
asyncio_run(init_db())
logger.debug("初始化数据库成功")
Expand Down
7 changes: 7 additions & 0 deletions backend/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from utils.db import jianshu_pool, jpep_pool, jtools_pool


async def init_db() -> None:
await jianshu_pool.prepare()
await jpep_pool.prepare()
await jtools_pool.prepare()

0 comments on commit b079a65

Please sign in to comment.