Add database init/close lifecycle events to app startup
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user