From a34fff3aaa509f21d7577406d108ea4d741d7c7f Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 11 Jan 2026 12:52:29 +0000 Subject: [PATCH] Add database init/close lifecycle events to app startup Co-Authored-By: Claude Opus 4.5 --- app/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index e906f7e..dd7a979 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,6 +26,17 @@ def create_app() -> FastAPI: version="1.0.0", ) + # Database lifecycle events + from database import init_db, close_db + + @app.on_event("startup") + async def startup(): + await init_db() + + @app.on_event("shutdown") + async def shutdown(): + await close_db() + # Initialize Jinja2 templates template_dir = Path(__file__).parent / "templates" app.state.templates = create_jinja_env(template_dir)