Миграции вынесены из команды api в one-shot сервис migrate, api и worker стартуют после него. /health отвечает 503 при недоступной БД. Отчёт больше MAX_UPLOAD_BYTES (25 МиБ) получает 413, Caddy режет на 30 МБ раньше. Том uploads убран, секреты env_file передаются сервисам явно. В CI добавлена сборка образа бэкенда без push, test_migrations сверяет модели с историей Alembic.
21 lines
870 B
Python
21 lines
870 B
Python
"""Models and Alembic history must describe the same schema — the `alembic check` of this
|
|
project. `migrated` upgrades a throwaway database to head, so a model change committed
|
|
without its revision shows up here as a non-empty diff."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from alembic.autogenerate import compare_metadata
|
|
from alembic.migration import MigrationContext
|
|
|
|
|
|
async def test_migrations_match_the_models(migrated: str):
|
|
import fintracker.models # noqa: F401 — registers every table on Base.metadata
|
|
from fintracker.db import get_engine
|
|
from fintracker.db.base import Base
|
|
|
|
async with get_engine().connect() as conn:
|
|
diff = await conn.run_sync(
|
|
lambda c: compare_metadata(MigrationContext.configure(c), Base.metadata)
|
|
)
|
|
assert diff == [], f"models changed without a migration (run `just revision`): {diff}"
|