fix: auto-resolve failed migrations in docker entrypoint
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m25s
All checks were successful
Build and Push Docker Image / build (push) Successful in 9m25s
On startup, check for any failed migration in _prisma_migrations and automatically mark it as rolled-back before running migrate deploy. This prevents a partially-applied migration from permanently blocking all future deployments. Also reduce max retries from 30 to 6. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,21 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
MAX_MIGRATION_RETRIES="${MIGRATION_MAX_RETRIES:-30}"
|
MAX_MIGRATION_RETRIES="${MIGRATION_MAX_RETRIES:-6}"
|
||||||
MIGRATION_RETRY_DELAY_SECONDS="${MIGRATION_RETRY_DELAY_SECONDS:-2}"
|
MIGRATION_RETRY_DELAY_SECONDS="${MIGRATION_RETRY_DELAY_SECONDS:-2}"
|
||||||
ATTEMPT=1
|
ATTEMPT=1
|
||||||
|
|
||||||
|
# Auto-resolve any previously failed migrations so deploy can proceed.
|
||||||
|
# This handles the case where a migration partially applied and was fixed
|
||||||
|
# in a subsequent deploy — without this, Prisma refuses to run anything.
|
||||||
|
echo "==> Checking for failed migrations..."
|
||||||
|
MIGRATE_STATUS=$(npx prisma migrate status 2>&1 || true)
|
||||||
|
FAILED=$(echo "$MIGRATE_STATUS" | sed -n 's/.*The `\([^`]*\)` migration.*failed.*/\1/p' | head -1)
|
||||||
|
if [ -n "$FAILED" ]; then
|
||||||
|
echo "==> Found failed migration: $FAILED — marking as rolled back..."
|
||||||
|
npx prisma migrate resolve --rolled-back "$FAILED"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "==> Running database migrations (with retry)..."
|
echo "==> Running database migrations (with retry)..."
|
||||||
until npx prisma migrate deploy; do
|
until npx prisma migrate deploy; do
|
||||||
if [ "$ATTEMPT" -ge "$MAX_MIGRATION_RETRIES" ]; then
|
if [ "$ATTEMPT" -ge "$MAX_MIGRATION_RETRIES" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user