Python
FastAPI
PostgreSQL
PyTest
Docker
- Create ".env" file and add environment variables to it:
# base
SECRET_KEY=some-secret-key
PROJECT_NAME='Some Project Name'
SERVER_HOST=http://0.0.0.0:8881
# databases
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=postgres
POSTGRES_DB=postgres
POSTGRES_TEST_DB=test
PGDATA=/var/lib/postgresql/data/pgdata
# SMTP
SMTP_USER=some-email
SMTP_PASSWORD=some-password
# Auth
FIRST_SUPERUSER_USERNAME=[email protected]
FIRST_SUPERUSER_PASSWORD=password
FIRST_SUPERUSER_FIRST_NAME='first name'
FIRST_SUPERUSER_LAST_NAME='last name'
Run server with all dependencies:
$ docker-compose up --build
Add pre-commit hook
$ pre-commit install
Testing is done with pytest, tests are placed in the "tests" directory
For testing, you should go inside the container and run the command pytest .
$ docker exec -it <FastAPI container ID> bash
$ pytest tests --asyncio-mode=auto
- After creating the model in
app/models
, you need to import it inapp/db/base.py
(in order to make it visible to alembic) - Make migrations (run inside container)
$ alembic -n postgres revision --autogenerate -m "add column last_name to User model"
- Run migrations
$ alembic -n postgres upgrade head
- Postgres
$ alembic -n postgres revision --autogenerate -m "text"
$ alembic -n postgres upgrade head
$ alembic -n postgres downgrade -1