1- # FastAPI_super_template
1+ # app
22
33This project was generated using fastapi_template.
44
@@ -11,7 +11,7 @@ To run the project use this set of commands:
1111
1212``` bash
1313poetry install
14- poetry run python -m src
14+ poetry run python -m app
1515```
1616
1717This will start the server on the configured host.
@@ -46,10 +46,13 @@ docker-compose build
4646## Project structure
4747
4848``` bash
49- $ tree " FastAPI_super_template "
50- src
49+ $ tree " app "
50+ app
5151├── conftest.py # Fixtures for all tests.
52- ├── main.py # Startup script. Starts uvicorn.
52+ ├── db # module contains db configurations
53+ │ ├── dao # Data Access Objects. Contains different classes to interact with database.
54+ │ └── models # Package contains different models for ORMs.
55+ ├── __main__.py # Startup script. Starts uvicorn.
5356├── services # Package for different external services such as rabbit or redis etc.
5457├── settings.py # Main configuration settings for project.
5558├── static # Static content.
@@ -68,18 +71,18 @@ This application can be configured with environment variables.
6871You can create ` .env ` file in the root directory and place all
6972environment variables here.
7073
71- All environment variables should start with "FASTAPI_SUPER_TEMPLATE _ " prefix.
74+ All environment variables should start with "APP _ " prefix.
7275
73- For example if you see in your "FastAPI_super_template /settings.py" a variable named like
74- ` random_parameter ` , you should provide the "FASTAPI_SUPER_TEMPLATE_RANDOM_PARAMETER "
76+ For example if you see in your "app /settings.py" a variable named like
77+ ` random_parameter ` , you should provide the "APP_RANDOM_PARAMETER "
7578variable to configure the value. This behaviour can be changed by overriding ` env_prefix ` property
76- in ` FastAPI_super_template .settings.Settings.Config` .
79+ in ` app .settings.Settings.Config` .
7780
7881An example of .env file:
7982``` bash
80- FASTAPI_SUPER_TEMPLATE_RELOAD =" True"
81- FASTAPI_SUPER_TEMPLATE_PORT =" 8000"
82- FASTAPI_SUPER_TEMPLATE_ENVIRONMENT =" dev"
83+ APP_RELOAD =" True"
84+ APP_PORT =" 8000"
85+ APP_ENVIRONMENT =" dev"
8386```
8487
8588You can read more about BaseSettings class here: https://pydantic-docs.helpmanual.io/usage/settings/
@@ -134,7 +137,40 @@ If you haven't pushed to docker registry yet, you can build image locally.
134137
135138``` bash
136139docker-compose build
137- docker save --output src.tar src:latest
140+ docker save --output app.tar app:latest
141+ ```
142+
143+ ## Migrations
144+
145+ If you want to migrate your database, you should run following commands:
146+ ``` bash
147+ # To run all migrations until the migration with revision_id.
148+ alembic upgrade " <revision_id>"
149+
150+ # To perform all pending migrations.
151+ alembic upgrade " head"
152+ ```
153+
154+ ### Reverting migrations
155+
156+ If you want to revert migrations, you should run:
157+ ``` bash
158+ # revert all migrations up to: revision_id.
159+ alembic downgrade < revision_id>
160+
161+ # Revert everything.
162+ alembic downgrade base
163+ ```
164+
165+ ### Migration generation
166+
167+ To generate migrations you should run:
168+ ``` bash
169+ # For automatic change detection.
170+ alembic revision --autogenerate
171+
172+ # For empty file generation.
173+ alembic revision
138174```
139175
140176
@@ -148,6 +184,12 @@ docker-compose down
148184```
149185
150186For running tests on your local machine.
187+ 1 . you need to start a database.
188+
189+ I prefer doing it with docker:
190+ ```
191+ docker run -p "5432:5432" -e "POSTGRES_PASSWORD=app" -e "POSTGRES_USER=app" -e "POSTGRES_DB=app" postgres:16.3-bullseye
192+ ```
151193
152194
1531952 . Run the pytest.
0 commit comments