fix(ci): add migration baseline to deploy job
All checks were successful
Deploy API Server / build-and-unit (push) Successful in 31s
Deploy API Server / current-integration (push) Successful in 2m59s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / deploy (push) Successful in 1m1s

- deploy job now handles missing _prisma_migrations (same as current-integration)
- Protects against MySQL restart between CI jobs clearing baseline

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-20 13:46:35 +08:00
parent f50d88ecf6
commit 7d4a774d4f

View File

@ -271,6 +271,17 @@ jobs:
- name: Apply database migrations - name: Apply database migrations
run: | run: |
cd $WORKDIR cd $WORKDIR
HAS_MIGS=$(npx prisma db execute --stdin <<< "SELECT COUNT(*) as cnt FROM _prisma_migrations" 2>/dev/null | grep -o '[0-9]*' | head -1 || echo "0")
if [ "$HAS_MIGS" = "0" ] || [ -z "$HAS_MIGS" ]; then
echo "[deploy] Baselining existing migrations..."
for m in prisma/migrations/*/; do
m_name=$(basename "$m")
if [ "$m_name" != "backfill_chat_scope.sql" ] && [ "$m_name" != "migration_lock.toml" ]; then
DATABASE_URL="${{ secrets.DATABASE_URL }}" npx prisma migrate resolve --applied "$m_name" 2>/dev/null || true
fi
done
echo "[deploy] Baseline complete."
fi
DATABASE_URL="${{ secrets.DATABASE_URL }}" npx prisma migrate deploy DATABASE_URL="${{ secrets.DATABASE_URL }}" npx prisma migrate deploy
env: env:
DATABASE_URL: ${{ secrets.DATABASE_URL }} DATABASE_URL: ${{ secrets.DATABASE_URL }}