We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f8d4bf4 commit 1410af5Copy full SHA for 1410af5
app.py
@@ -6,11 +6,18 @@
6
7
@asynccontextmanager
8
async def lifespan(app: FastAPI):
9
- await engine.connect()
10
- yield
11
- # You can also close DB connections here if needed
12
- print("App shutdown complete.")
+ print("🚀 App starting...")
+
+ # ✅ Properly open a connection context
+ async with engine.begin() as conn:
13
+ # optional: run startup scripts (like create_all)
14
+ pass
15
16
+ yield # App is running
17
18
+ print("🧹 App shutting down...")
19
await engine.dispose()
20
+ print("✅ App shutdown complete.")
21
22
23
app = FastAPI(lifespan=lifespan, description="Template for building FastAPI applications with PostgreSQL", contact={"email": "samanidarix@gmail.com"})
0 commit comments