generated from nyeki/uv-fastapi-tortoise
Initial commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
from tortoise import Tortoise
|
||||
from tortoise.migrations import api as migrations
|
||||
|
||||
from project.lib import settings
|
||||
|
||||
|
||||
async def on_startup():
|
||||
"""Connects to the database and creates the missing schemas on FastAPI startup."""
|
||||
|
||||
await migrations.migrate(config=settings.DATABASE)
|
||||
await Tortoise.init(config=settings.DATABASE, _enable_global_fallback=True)
|
||||
|
||||
|
||||
async def on_shutdown():
|
||||
"""Closes the database connections on FastAPI shutdown."""
|
||||
|
||||
await Tortoise.close_connections()
|
||||
Reference in New Issue
Block a user