Skip to content

Latest commit

 

History

History
94 lines (56 loc) · 3.93 KB

development.md

File metadata and controls

94 lines (56 loc) · 3.93 KB

Alembic SQLite CI/CD

Interface translations

To add a language, copy the English catalog to a file named for the new two-letter ISO 639-1 code, such as nl.json. Translate the values and preserve the keys and format placeholders. Then register the code and its native name in LANGUAGES in texts.py. The picker and Telegram command menu use that registry.

🗄️ Database migrations

The project uses Alembic to manage the SQLite schema.

How the schema is applied

At runtime the database schema is created or upgraded by calling backend.storage.db.init_db(). It uses the Alembic Python API to upgrade to head. The equivalent CLI command is:

python -m alembic -c backend/alembic.ini upgrade head

Every entrypoint that needs a database should call init_db() once before using the storage layer.

Running migrations locally

From the project root, set BOT_TOKEN in .env or in the environment, then run:

python -m alembic -c backend/alembic.ini upgrade head

This upgrades the database pointed to by backend.storage.db.DB_PATH to the latest migration.

Creating a new migration

When you change the database schema, you must add a new Alembic migration.

The recommended workflow is:

  1. Edit the schema in code only after the migration is created and applied.

  2. Create a new migration file:

    python -m alembic -c backend/alembic.ini revision -m "describe_change"
  3. Edit the generated revision file in backend/alembic/versions/ and write the upgrade and downgrade functions using raw SQL for SQLite.

  4. Apply the migration:

    python -m alembic -c backend/alembic.ini upgrade head

SQLite support is limited for automatic schema diffs, so migrations are written by hand.

Migrations and tests

Tests that rely on the database use the same migrations:

  • backend.storage.db.DB_PATH can be patched to point to a temporary file.

  • backend.storage.db.init_db() is called to apply all migrations to that temporary database.

Storage integration tests use the Alembic revisions against temporary SQLite databases.

Docker and migrations

The Docker entrypoint applies the migrations before starting the bot:

python -m alembic -c backend/alembic.ini upgrade head
python bot.py

CI pipeline

On pushes to main or master and pull requests targeting either branch, CI uses Python 3.11, installs .[dev], applies migrations with a test token, and runs pre-commit and mypy. It then runs two test groups:

pytest --import-mode=importlib -m "not storage_db"
pytest --import-mode=importlib -m "storage_db" --no-cov

Coverage enforces a minimum of 80%. Docker Build and Compose check image and container setup. The Docker healthcheck verifies Python imports. Docs checks links when documentation changes. Security runs Bandit, pip-audit, and Trivy on the same branches and weekly.

Release publishes the Docker image to GHCR for v* tags using GITHUB_TOKEN. It creates a GitHub Release only for tags matching vX.0.0.