managarten/services/mana-core-auth/docker-entrypoint.sh
Wuesteon 9e771c9ae2 🔧 chore(auth): improve migration safety and docker setup
- Add safe-db-push.mjs script for safer database migrations
- Update docker-entrypoint.sh with db:push fallback when migrations fail
- Add validate-migrations.mjs script for CI migration validation
- Update CI workflow to use migration validation
- Update drizzle.config.ts with improved configuration
2025-12-19 02:18:31 +01:00

36 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
set -e
# Run database migrations using proper migration files
# This is SAFE - only applies versioned migration files, never drops tables
echo "📋 Running database migrations..."
# Wait for PostgreSQL to be ready (up to 60 seconds)
MAX_RETRIES=30
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# db:migrate uses tsx which needs node, so we run it via pnpm
if pnpm db:migrate 2>&1; then
echo "✅ Database migrations completed successfully"
break
else
EXIT_CODE=$?
RETRY_COUNT=$((RETRY_COUNT + 1))
# Check if it's a connection error (exit code is typically non-zero for connection issues)
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "⏳ Database not ready or migration in progress, retrying in 2 seconds... ($RETRY_COUNT/$MAX_RETRIES)"
sleep 2
else
echo "❌ Failed to run database migrations after $MAX_RETRIES attempts"
echo " Exit code: $EXIT_CODE"
echo " Check database connectivity and migration files"
exit 1
fi
fi
done
# Start the application
echo "🚀 Starting Mana Core Auth..."
exec node dist/main.js