Files
marriage/.history/fix_alembic_20250808201241.sh
Andrey K. Choi cc87dcc0fa
Some checks failed
continuous-integration/drone/push Build is failing
api development
2025-08-08 21:58:36 +09:00

55 lines
1.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
set -euo pipefail
SERVICES=(auth profiles match chat payments)
# Добавим импорт моделей в env.py, если его нет
for s in "${SERVICES[@]}"; do
ENV="services/$s/alembic/env.py"
if ! grep -q "from app import models" "$ENV"; then
# вставим строку сразу после импорта Base
awk '
/from app\.db\.session import Base/ && !x {print; print "from app import models # noqa: F401"; x=1; next}
{print}
' "$ENV" > "$ENV.tmp" && mv "$ENV.tmp" "$ENV"
echo "[fix] added 'from app import models' to $ENV"
fi
done
# Создадим шаблон mako для Alembic в каждом сервисе (если отсутствует)
for s in "${SERVICES[@]}"; do
TPL="services/$s/alembic/script.py.mako"
if [[ ! -f "$TPL" ]]; then
mkdir -p "$(dirname "$TPL")"
cat > "$TPL" <<'MAKO'
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '${up_revision}'
down_revision: Union[str, None] = ${down_revision | repr}
branch_labels: Union[str, Sequence[str], None] = ${branch_labels | repr}
depends_on: Union[str, Sequence[str], None] = ${depends_on | repr}
def upgrade() -> None:
pass
def downgrade() -> None:
pass
MAKO
echo "[fix] created $TPL"
fi
done
echo "✅ Alembic templates fixed."
echo "Совет: предупреждение docker-compose про 'version' можно игнорировать или удалить строку 'version: \"3.9\"' из docker-compose.yml."