From 64880499235d6a38fb720453a5db91e4645846ed Mon Sep 17 00:00:00 2001 From: WangDL Date: Mon, 18 May 2026 15:00:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20failed=20Prisma=20migration=20?= =?UTF-8?q?=E2=80=94=20cleanup=20partial=20state=20before=20re-deploy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .gitea/workflows/deploy.yml | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index b4393b0..4ddc1b0 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -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: |