This repository is used to run the backend of meticulous.
To allow developers to run the backend without a physical coffee machine, we have implemented a Docker configuration. Follow these steps:
# Branch
git fetch origin
git switch main
# Docker compose
docker compose run --build -p 8080:8080 backend
if you are on linux, just start the backend directly:
BACKEND=emulator python3 back.py
You can interact with the backend using the command line interface after run the docker compose command. For instance, you can enter the commands
l
and
r
to move the dial. These commands will shift the dial to the left or right, respectively.
This project uses Alembic for managing database migrations. Follow these steps to handle any changes in the database structure:
-
Modify Database Models:
Editdatabase_models.py
to reflect the required changes in your database structure. You can:- Add or modify tables, columns, or constraints.
- Remember, this file is the single source of truth for the database schema.
-
Generate a Migration Script:
Run the following command to create a new migration script:alembic revision --autogenerate -m "Brief description of change"
- A new script will be generated in the
alembic/versions
directory. - Open the generated script and review the
upgrade()
anddowngrade()
functions. - Ensure these functions accurately reflect your intended changes, and modify them if necessary.
- A new script will be generated in the
-
Apply the Migration:
Update your local database to the latest version with:alembic upgrade head
- Simply push your changes to the
main
branch. - Other machines will automatically apply the migrations using the
db_migration_updater.py
script.
If you need to revert to a previous database version:
-
Identify the Revision:
Find the desired revision ID from the scripts in thealembic/versions
directory. -
Set the Stable Version:
Update the version indb_migration_updater.py
:MIGRATION_VERSION_STABLE = "revision_id" # e.g., "ebb6a77afd0e"
-
Automatic Downgrade:
The system will automatically downgrade the database to the specified version.
- Testing: Always test your migration scripts locally before deploying them.
- Collaboration: Communicate with your team when making significant changes to the database schema.
- Documentation: Keep your migration messages clear to track the evolution of the database.