This commit is contained in:
MaKarin
2026-04-04 20:06:21 +03:00
parent cf53ab8cf9
commit 698bc64d41
2 changed files with 22 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ services:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-change-me}
POSTGRES_DB: ${POSTGRES_DB:-toir}
# UTF-8 cluster (applies only on first volume init) — migrations use Cyrillic enum labels
POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --locale=C.UTF-8"
healthcheck:
test:
[
@@ -64,7 +66,8 @@ services:
restart: unless-stopped
depends_on:
server:
condition: service_healthy
# Do not wait for healthy: if migrations fail, stack stays up so you can read server logs.
condition: service_started
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1/healthz >/dev/null 2>&1 || exit 1"]
interval: 15s

View File

@@ -2,20 +2,35 @@
set -e
PRISMA_BIN="./node_modules/.bin/prisma"
SCHEMA="prisma/schema.prisma"
if [ ! -f "$PRISMA_BIN" ]; then
echo "Prisma CLI not found at $PRISMA_BIN"
exit 1
fi
echo "Applying database migrations..."
export PRISMA_HIDE_UPDATE_MESSAGE=1
run_migrate() {
"$PRISMA_BIN" migrate deploy --schema "$SCHEMA" --skip-generate
}
echo "Applying database migrations (schema=$SCHEMA)..."
i=0
while [ "$i" -lt 15 ]; do
if "$PRISMA_BIN" migrate deploy; then
if run_migrate; then
break
fi
i=$((i + 1))
if [ "$i" -eq 15 ]; then
echo "prisma migrate deploy failed after 15 attempts"
echo "----------------------------------------------------------------"
echo "prisma migrate deploy failed after 15 attempts."
echo "Check: docker logs toir-server"
echo "If the DB volume has a broken migration history, remove volume"
echo "kis-toir_postgres-data once (all DB data lost) or fix _prisma_migrations."
echo "--- prisma migrate status ---"
"$PRISMA_BIN" migrate status --schema "$SCHEMA" || true
echo "----------------------------------------------------------------"
exit 1
fi
echo "Migrate failed or DB not ready; retrying in 2s ($i/15)..."