Template
mirror of
https://github.com/Nekidev/uv-fastapi-tortoise.git
synced 2026-09-12 19:57:25 +00:00
Add versioning support by default, replace _Project.md with _Summary.md and _Description.md, upgrade to the latest Tortoise ORM version
This commit is contained in:
+5
-17
@@ -1,8 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from aerich import Command
|
||||
|
||||
from tortoise import Tortoise, connections
|
||||
from tortoise import Tortoise
|
||||
from tortoise.migrations import api as migrations
|
||||
|
||||
from project.lib import settings
|
||||
|
||||
@@ -10,20 +7,11 @@ from project.lib import settings
|
||||
async def on_startup():
|
||||
"""Connects to the database and creates the missing schemas on FastAPI startup."""
|
||||
|
||||
async with Command(
|
||||
tortoise_config=settings.DATABASE, app="models", location="project/db/migrations"
|
||||
) as command:
|
||||
parent_dir = Path(__file__).parent
|
||||
|
||||
if not (parent_dir / "migrations").exists():
|
||||
await command.init_migrations(safe=True)
|
||||
|
||||
await command.upgrade()
|
||||
|
||||
await Tortoise.init(config=settings.DATABASE)
|
||||
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 connections.close_all()
|
||||
await Tortoise.close_connections()
|
||||
|
||||
Reference in New Issue
Block a user