fix: resolve failed Prisma migration — cleanup partial state before re-deploy
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 15s

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
WangDL 2026-05-18 15:00:59 +08:00
parent 9e5fb7cb40
commit 6488049923

View File

@ -37,7 +37,38 @@ jobs:
break
fi
done
sleep 3
sleep 5
- name: Resolve failed migrations
run: |
MYSQL_PASS=$(docker exec mysql-zhixi printenv MYSQL_PASSWORD 2>/dev/null || echo "Zhixi@2026!App")
MYSQL_CMD="docker exec mysql-zhixi mysql -u zhixi_user -p'$MYSQL_PASS' zhixi"
# Check for failed/stuck migrations
FAILED=$($MYSQL_CMD -N -e \
"SELECT migration_name FROM _prisma_migrations WHERE logs LIKE '%failed%' LIMIT 1;" 2>/dev/null || true)
if [ -n "$FAILED" ]; then
echo "[deploy] Found failed migration: $FAILED, cleaning up partially-created objects..."
# Drop new tables from the migration (IF EXISTS is safe)
$MYSQL_CMD -e "DROP TABLE IF EXISTS AiUsageLog;" 2>/dev/null || true
$MYSQL_CMD -e "DROP TABLE IF EXISTS WaitlistEntry;" 2>/dev/null || true
# Drop new columns from UploadedFile (ignore errors if they don't exist)
$MYSQL_CMD -e "ALTER TABLE UploadedFile DROP COLUMN objectKey;" 2>/dev/null || true
$MYSQL_CMD -e "ALTER TABLE UploadedFile DROP COLUMN bucket;" 2>/dev/null || true
# Drop index (ignore error if not exists)
$MYSQL_CMD -e "DROP INDEX UploadedFile_objectKey_idx ON UploadedFile;" 2>/dev/null || true
# Remove the failed migration record so Prisma can re-apply it
$MYSQL_CMD -e "DELETE FROM _prisma_migrations WHERE migration_name = '$FAILED';"
echo "[deploy] Cleaned up failed migration $FAILED"
else
echo "[deploy] No failed migrations found"
fi
- name: Start new container
run: |