This document provides instructions to set up and run the backend service, including database migrations using Alembic and Docker.
Make sure you have the following installed on your system:
Follow the steps below to set up the backend project:
If Alembic has not been initialized in your project, you can do so by running:
alembic init alembic
This will create the necessary Alembic configuration files in your project directory.
To build the Docker images for your application, execute:
docker-compose build
This will build all the services defined in your docker-compose.yml
file.
To start the application services, run:
docker-compose up
This will start all the services (e.g., app, database) in the foreground. You can add the -d
flag to run the services in detached mode:
docker-compose up -d
To create a new database migration, use the following command:
docker-compose run app alembic revision --autogenerate -m "Migration name"
Replace "Migration name"
with a descriptive name for your migration.
Apply the migration to the database with:
docker-compose run app alembic upgrade head
This will upgrade your database schema to the latest version.
- Ensure that your Alembic configuration (
alembic.ini
) and.env
file are correctly set up to connect to your database. - If you encounter any issues, check the logs by running
docker-compose logs
.
Here are some additional helpful commands:
-
Stop all services:
docker-compose down
-
Rebuild services after changes:
docker-compose up --build
-
View logs for a specific service:
docker-compose logs <service_name>
-
Access the running app container:
docker-compose exec app /bin/bash