de973f5613
Test and Lint / backend-test (push) Successful in 1m9s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m15s
Version and Release / version-bump (push) Successful in 36s
Version and Release / trigger-drone (push) Successful in 4s
Major fixes for production deployment issues: 1. Migration System: - Add safe migration runner that handles existing schema - Create migration helper functions for idempotent operations - Auto-detect existing tables and mark migrations as applied - Handle "relation already exists" errors gracefully 2. Production Initialization: - Create init-production.sh script for proper startup sequence - Fix directory creation and permissions - Add admin user creation from environment variables - Ensure proper service initialization order 3. Documentation: - Add comprehensive PRODUCTION_DEPLOYMENT_GUIDE.md - Add MIGRATION_ERROR_FIX.md for immediate issue resolution - Document all known production issues and solutions - Include backup/restore procedures 4. Safety Improvements: - Add migrate:safe npm script for production use - Update wait-for-db.sh to use safe migrations in production - Add proper error handling and logging This resolves the "relation already exists" error and prevents similar issues in future deployments. The safe migration system can handle both fresh installations and existing databases. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
50 lines
1.5 KiB
Bash
Executable File
50 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# init-production.sh - Production initialization script
|
|
|
|
set -e
|
|
|
|
echo "🚀 Initializing PicPeak Production Environment..."
|
|
|
|
# Wait for services to be ready
|
|
echo "⏳ Waiting for database to be fully ready..."
|
|
sleep 3
|
|
|
|
# Fix permissions if running as root (shouldn't happen with proper Dockerfile)
|
|
if [ "$(id -u)" = "0" ]; then
|
|
echo "🔧 Fixing file permissions..."
|
|
chown -R nodejs:nodejs /app/storage /app/data /app/logs 2>/dev/null || true
|
|
fi
|
|
|
|
# Create required directories
|
|
echo "📁 Creating required directories..."
|
|
mkdir -p /app/storage/events/active \
|
|
/app/storage/events/archived \
|
|
/app/storage/thumbnails \
|
|
/app/storage/uploads/logos \
|
|
/app/storage/uploads/favicons \
|
|
/app/data \
|
|
/app/logs
|
|
|
|
# Run migrations with safe runner
|
|
echo "🗄️ Running database migrations (safe mode)..."
|
|
NODE_ENV=production npm run migrate:safe
|
|
|
|
# Create admin user if environment variables are set
|
|
if [ -n "$ADMIN_EMAIL" ] && [ -n "$ADMIN_PASSWORD" ]; then
|
|
echo "👤 Creating admin user..."
|
|
node scripts/create-admin.js \
|
|
--email "$ADMIN_EMAIL" \
|
|
--username "${ADMIN_USERNAME:-admin}" \
|
|
--password "$ADMIN_PASSWORD" || echo "Admin user might already exist"
|
|
fi
|
|
|
|
# Initialize email configuration if variables are set
|
|
if [ -n "$SMTP_HOST" ]; then
|
|
echo "📧 Email configuration detected via environment variables"
|
|
fi
|
|
|
|
echo "✅ Production initialization complete!"
|
|
echo "🌐 Starting application server..."
|
|
|
|
# Start the application
|
|
exec node server.js |