Quick example of FastAPI with Tortoise and Aerich (for migration support).
Build the image and spin up the web
(FastAPI + Uvicorn) and web-db
(Postgres) containers:
$ docker-compose up -d --build
Ensure http://localhost:8002/ping works:
{
"ping": "pong!"
}
Init Aerich:
$ docker-compose exec web aerich init -t db.TORTOISE_ORM
Create the first migration and apply it to the database:
$ docker-compose exec web aerich init-db
Make a change to the model. Then, run:
$ docker-compose exec web aerich migrate
$ docker-compose exec web aerich upgrade
Want to access the database via psql?
$ docker-compose exec web-db psql -U postgres
Then, you can connect to the database and run SQL queries. For example:
# \c web
# select * from event;