This is the backend repository for FinAdvisor.
This guide provides step-by-step instructions to set up your project, configure the database, and manage database migrations using Alembic and Docker.
Ensure you have the following installed on your system:
- Python (preferably 3.6+)
- Docker
- Docker Compose
First, install Alembic, a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.
pip install alembic
Set the SQLAlchemy URL in the alembic.ini
file to point to your local PostgreSQL instance.
# alembic.ini
[alembic]
sqlalchemy.url = postgresql://postgres:postgres@localhost:5432/postgres
Create a .env
file in the root directory of your project and add the following environment variables.
# .env
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
SECRET_KEY=[Ask Advait]
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
OPENAI_API_KEY=[Get your own!]
Use Docker Compose to build and run the PostgreSQL database container.
docker-compose up -d db
Generate the initial database migration script using Alembic.
alembic revision --autogenerate -m "Initial migration"
Apply the generated migration to update the database schema.
alembic upgrade head
After applying the migration, update the database URLs to point to the Docker container.
set sqlalchemy.url=postgresql://postgres:postgres@db:5432/postgres
set DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
Build and run the Docker containers for your application.
docker-compose up -d --build
When you are done, stop the database container.
docker-compose down