|
| 1 | +# NewsPicking-Backend |
| 2 | + |
| 3 | +## 🛠 Skills |
| 4 | +Python, Fask-API, Swagger Doc, Html and Java Scripts. |
| 5 | + |
| 6 | +## Install + configure the project |
| 7 | + |
| 8 | +### 1. Linux |
| 9 | +``` |
| 10 | +# Create python virtual environment |
| 11 | +python3 -m venv venv |
| 12 | +
|
| 13 | +# Activate the python virtual environment |
| 14 | +source venv/bin/activate |
| 15 | +
|
| 16 | +# Install the requirements for the project into the virtual environment |
| 17 | +pip install -r requirements.txt |
| 18 | +
|
| 19 | +# Install the dependencies of Fast API |
| 20 | +pip install "fastapi[all]" |
| 21 | +
|
| 22 | +# Upgrade pip version |
| 23 | +python -m pip install --upgrade pip==22.1.2 |
| 24 | +``` |
| 25 | +### 2. Windows |
| 26 | +``` |
| 27 | +# Create python virtual environment |
| 28 | +conda create --name venv python=3.10.12 |
| 29 | +
|
| 30 | +# Activate the python virtual environment |
| 31 | +conda activate venv |
| 32 | +
|
| 33 | +# Install the requirements for the project into the virtual environment in the following sequence: |
| 34 | +pip install -r requirements.txt |
| 35 | +
|
| 36 | +# Install the dependencies of Fast API |
| 37 | +pip install "fastapi[all]" |
| 38 | +
|
| 39 | +# Upgrade pip version |
| 40 | +python -m pip install --upgrade pip==22.1.2 |
| 41 | +``` |
| 42 | + |
| 43 | +## Use the alembic to Upgrade/Downgrade the database in the FastAPI |
| 44 | +Note: Because by default Fastapi is provide only initial migrations. It doesn't support the upgrade and downgrade the database. |
| 45 | +so,to perform automatic migrations follow the following steps: |
| 46 | + |
| 47 | +1. # To create Migration folder |
| 48 | +python -m alembic init migrations |
| 49 | + |
| 50 | +2. ## update the Migrations>>env.py file o auto migrate the database. |
| 51 | +from models import Base |
| 52 | +target_database = Base.metadata |
| 53 | + |
| 54 | +4. # Perform the initial migrations |
| 55 | +alembic revision --autogenerate -m 'initials' |
| 56 | + |
| 57 | +5. # Apply the changes into the database (upgrade the database) |
| 58 | +alembic upgrade head |
| 59 | + # To downgrade the database if required |
| 60 | + alembic downgrade -1 |
| 61 | + |
| 62 | +## Run the server in development mode |
| 63 | + |
| 64 | +Add environment variables (given in .env) by running following command in cmd/terminal: |
| 65 | + |
| 66 | +Run the server |
| 67 | +``` |
| 68 | +python asgi.py |
| 69 | +``` |
| 70 | +Browse Swagger API Doc at: http://localhost:8000/docs |
| 71 | +Browse Redoc at: http://localhost:8000/redoc |
| 72 | + |
| 73 | +## Release History |
| 74 | + |
| 75 | +* 0.1 |
| 76 | + * Work in progress |
0 commit comments