/fastapi-example

Primary LanguagePythonMIT LicenseMIT

Generate migrations (online)

On Postgres 15, give rights on public schema for the current user:

GRANT ALL ON SCHEMA public TO dev;

Next, generate the migrations:

alembic revision --autogenerate -m "New Migration"

Update the database (run migrations)

alembic upgrade head

Run the API

uvicorn main:app --reload

Next, go to SWAGGER UI http://localhost:8000/docs

Docker

Build the image:

docker build -t fastapi .

Then, run the image:

docker run -e DATABASE_URL='postgresql://driver://user:pass@localhost/dbname' -p 8080:8080 fastapi

Links

https://www.educative.io/answers/how-to-use-postgresql-database-in-fastapi