From 327d3a95a3bd855b75aa17ee522475d8b27613cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Tue, 21 Apr 2026 00:55:29 +0300 Subject: [PATCH] Refactor Prisma migration handling in docker-entrypoint.sh - Introduced a function to handle schema synchronization with prisma db push. - Enhanced migration logic to fall back to db push if migration fails with P3005 error. - Improved logging for migration processes to aid in debugging. --- server/docker-entrypoint.sh | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/server/docker-entrypoint.sh b/server/docker-entrypoint.sh index 7f715fa..f373c40 100644 --- a/server/docker-entrypoint.sh +++ b/server/docker-entrypoint.sh @@ -1,12 +1,37 @@ #!/bin/sh set -eu -if [ -d "prisma/migrations" ] && [ -n "$(find prisma/migrations -mindepth 1 -maxdepth 1 -type d 2>/dev/null)" ]; then - echo "Applying Prisma migrations with migrate deploy..." - npx prisma migrate deploy -else - echo "No Prisma migrations found, syncing schema with db push..." +run_db_push() { + echo "Syncing schema with prisma db push..." npx prisma db push +} + +if [ ! -d "prisma/migrations" ] || [ -z "$(find prisma/migrations -mindepth 1 -maxdepth 1 -type d 2>/dev/null)" ]; then + echo "No Prisma migrations found, syncing schema with db push..." + run_db_push +else + echo "Applying Prisma migrations with migrate deploy..." + MIGRATE_LOG="$(mktemp)" + set +e + npx prisma migrate deploy >"$MIGRATE_LOG" 2>&1 + MIGRATE_EXIT=$? + set -e + + if [ "$MIGRATE_EXIT" -eq 0 ]; then + cat "$MIGRATE_LOG" + rm -f "$MIGRATE_LOG" + elif grep -q P3005 "$MIGRATE_LOG"; then + cat "$MIGRATE_LOG" >&2 + echo "" >&2 + echo "prisma migrate deploy failed with P3005: database already has schema but no migration history (typical after prisma db push)." >&2 + echo "Falling back to prisma db push so the schema stays in sync." >&2 + rm -f "$MIGRATE_LOG" + run_db_push + else + cat "$MIGRATE_LOG" >&2 + rm -f "$MIGRATE_LOG" + exit "$MIGRATE_EXIT" + fi fi exec node dist/src/main.js