diff --git a/model.py b/model.py index 9f4d8ae..7c14479 100644 --- a/model.py +++ b/model.py @@ -60,6 +60,7 @@ class SioConfig(BaseModel): client_id: str client_secret: str localhost: str + db_url: str @dataclass diff --git a/server.py b/server.py index 9bfb228..55a87f1 100644 --- a/server.py +++ b/server.py @@ -6,6 +6,7 @@ from sanic import Sanic, Request from sanic.log import logger, Colors from sanic.response import text from socketio import AsyncClient +from tortoise.contrib.sanic import register_tortoise from command import command_convert from gitea_model import WebHookIssueComment, WebHookIssue, GiteaEvent @@ -21,9 +22,16 @@ def get_config() -> SioConfig: return SioConfig(**config) +SIO_CONFIG = get_config() + +register_tortoise( + app, db_url=SIO_CONFIG.db_url, modules={"models": ["orm"]}, generate_schemas=True +) + + @app.before_server_start async def setup_before_start(_app): - _app.ctx.sio_config = get_config() + _app.ctx.sio_config = SIO_CONFIG _app.ctx.sio = AsyncClient() start_sio_listener()