We have a lightweight integration util tortoise.contrib.fastapi which has a class RegisterTortoise that can be used to set/clean up Tortoise-ORM in lifespan context.
Initialize the migrations directory (one-time, already done in this example):
python -m tortoise -c config.TORTOISE_ORM initCreate migrations when models change:
python -m tortoise -c config.TORTOISE_ORM makemigrationsApply migrations to the database:
python -m tortoise -c config.TORTOISE_ORM migrateuvicorn main:app --reload