Skip to content

Commit 5ef6c5c

Browse files
README.md file update
1 parent 431fc9a commit 5ef6c5c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

BaseApp/UserApp/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
api = APIRouter()
55

66

7-
@api.get("/")
7+
@api.get("/index")
88
def index():
99
return {"key": "value"}

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
# FastApiArchitecture
22
FastApi Project Architecture with database and alembic tools
3+
4+
Create virtual environment then activate to install requirements libraries from requirements.txt
5+
6+
Project is set up in BaseApp folder. In this manager.py file have app configurations.
7+
8+
### Run FastApi Server
9+
I am using uvicorn server to run app
10+
11+
`uvicorn BaseApp.manager:app --reload`
12+
13+
Database migrations using alembic.
14+
15+
### Initialize alembic
16+
**db-migration** is folder name
17+
18+
`alembic init db-migration`
19+
20+
### Configure alembic for database and apps models
21+
Edit env.py file and change according to this repo env.py file.
22+
In this change Database url with environment variable and configure into mehod of run_migrations_offline and run_migrations_online.
23+
24+
### Change database url in **alembic.ini** file also
25+
26+
### Auto generate migration script
27+
import project app models all
28+
and import project database **Base**
29+
initialize it like this.
30+
31+
`target_metadata = Base.metadata`
32+
33+
Now we are connected with models for migrations.
34+
35+
### Now generate migration script with this
36+
This will scan the models and generate upgrade & downgrade scripts.
37+
38+
`alembic revision --autogenerate -m “message”`
39+
40+
### Run migration into database
41+
This upgrade your model columns into database.
42+
### Run upgrade command to migrate models
43+
`alembic upgrade head`
44+
45+
### Run downgrade command to drop models
46+
`alembic downgrade`
47+
48+

0 commit comments

Comments
 (0)