Improve migration error handling in entrypoint script: Enhance extraction of migration names from logs, add fallback mechanisms, and refine output messages for better clarity during deployment processes.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m21s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m21s
This commit is contained in:
@@ -23,30 +23,51 @@ deploy_migrations() {
|
|||||||
|
|
||||||
echo "Found failed migrations, attempting to resolve..."
|
echo "Found failed migrations, attempting to resolve..."
|
||||||
|
|
||||||
# Extract migration name from error (format: migration `20251210120000_add_event_feedback`)
|
# Extract migration name from error - look for text between backticks
|
||||||
# Using sed instead of grep -P for Alpine Linux compatibility
|
# Pattern: The `20251210120000_add_event_feedback` migration
|
||||||
MIGRATION_NAME=$(grep "migration \`" /tmp/migrate.log | sed -n "s/.*migration \`\([0-9_]*[a-z_]*\)\`.*/\1/p" | head -1)
|
MIGRATION_NAME=$(grep -oE "\`[0-9_]+[a-zA-Z_]+\`" /tmp/migrate.log | tr -d '\`' | head -1)
|
||||||
|
|
||||||
|
# If still not found, try without backticks (fallback)
|
||||||
|
if [ -z "$MIGRATION_NAME" ]; then
|
||||||
|
MIGRATION_NAME=$(grep "failed" /tmp/migrate.log | grep -oE "[0-9]{14}_[a-zA-Z_]+" | head -1)
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$MIGRATION_NAME" ]; then
|
if [ -z "$MIGRATION_NAME" ]; then
|
||||||
echo "Could not extract migration name from error"
|
echo "Could not extract migration name from error. Log content:"
|
||||||
|
cat /tmp/migrate.log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Resolving failed migration: $MIGRATION_NAME"
|
echo "Resolving failed migration: $MIGRATION_NAME"
|
||||||
|
|
||||||
# Try to resolve as applied (migration might have partially succeeded)
|
# Try to resolve as applied (migration might have partially succeeded)
|
||||||
if pnpm dlx prisma migrate resolve --applied "$MIGRATION_NAME" 2>&1; then
|
RESOLVE_OUTPUT=$(pnpm dlx prisma migrate resolve --applied "$MIGRATION_NAME" 2>&1)
|
||||||
|
RESOLVE_EXIT=$?
|
||||||
|
|
||||||
|
echo "$RESOLVE_OUTPUT"
|
||||||
|
|
||||||
|
if [ $RESOLVE_EXIT -eq 0 ]; then
|
||||||
echo "Migration resolved successfully, retrying deploy..."
|
echo "Migration resolved successfully, retrying deploy..."
|
||||||
# Retry migration deploy
|
# Retry migration deploy
|
||||||
pnpm dlx prisma migrate deploy || {
|
if pnpm dlx prisma migrate deploy 2>&1; then
|
||||||
echo "Migration deploy still failed after resolution, continuing anyway..."
|
echo "Migrations deployed successfully after resolution"
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
echo "Failed to resolve migration, but continuing..."
|
echo "Migration deploy still failed after resolution, but continuing..."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Check if migration is already marked as applied
|
||||||
|
if echo "$RESOLVE_OUTPUT" | grep -q "already recorded as applied"; then
|
||||||
|
echo "Migration is already marked as applied, retrying deploy..."
|
||||||
|
pnpm dlx prisma migrate deploy 2>&1 || true
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Failed to resolve migration: $RESOLVE_OUTPUT"
|
||||||
|
echo "Continuing anyway - app might still work if migration was partially applied"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Deploy migrations (don't fail if it errors - app might still work)
|
# Deploy migrations (don't fail if it errors - app might still work)
|
||||||
|
|||||||
Reference in New Issue
Block a user