Files
wecom-ai-assistant/deploy/scripts/migrate.sh
2026-02-05 16:36:32 +08:00

28 lines
676 B
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
# 一键迁移Docker在项目根目录执行
# 用法: bash deploy/scripts/migrate.sh 或 ./deploy/scripts/migrate.sh
set -e
cd "$(dirname "$0")/../.."
echo "[1/3] 启动数据库..."
docker compose up -d db
echo "[2/3] 等待数据库就绪..."
max=30
for i in $(seq 1 $max); do
if docker compose exec -T db pg_isready -U wecom -d wecom_ai 2>/dev/null; then
break
fi
if [ "$i" -eq "$max" ]; then
echo "数据库未在 ${max}s 内就绪,请检查 docker compose logs db"
exit 1
fi
sleep 1
done
echo "[3/3] 执行 Alembic 迁移..."
docker compose run --rm backend sh -c "alembic upgrade head"
echo "迁移完成。"