This commit is contained in:
54
scripts/fix_alembic.sh
Executable file
54
scripts/fix_alembic.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/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."
|
||||
Reference in New Issue
Block a user