fully working when deployed

This commit is contained in:
2025-09-28 18:47:31 +01:00
parent 38ee5a8886
commit d4aa460f91
9 changed files with 303 additions and 81 deletions
+76
View File
@@ -0,0 +1,76 @@
#!/bin/bash
set -e
echo "🚀 Starting TT Booking Production..."
# Create required directories if they don't exist
echo "📁 Ensuring directories exist..."
mkdir -p /app/data /app/backups /app/logs
chmod 755 /app/data /app/backups /app/logs
# Set defaults for environment variables
export DATABASE_URL="${DATABASE_URL:-/app/data/sqlite.db}"
export NODE_ENV="${NODE_ENV:-production}"
export ADMIN_EMAIL="${ADMIN_EMAIL:-admin@tabletennis.com}"
export ADMIN_PASSWORD="${ADMIN_PASSWORD:-admin123}"
# Validate required environment variables
if [ -z "$NEXTAUTH_SECRET" ]; then
echo "❌ NEXTAUTH_SECRET is required but not set"
echo "💡 Generate one with: openssl rand -base64 32"
exit 1
fi
if [ -z "$NEXTAUTH_URL" ]; then
echo "❌ NEXTAUTH_URL is required but not set"
echo "💡 Set to your application URL, e.g., https://your-domain.com"
exit 1
fi
# Check database state and determine what actions are needed
echo " Analyzing database state..."
DB_CHECK_EXIT=0
npx tsx scripts/check-database.ts || DB_CHECK_EXIT=$?
case $DB_CHECK_EXIT in
0)
echo "✅ Database is ready - no action needed"
;;
1)
echo " Database needs migration..."
npm run db:push
echo "✅ Migration completed"
;;
2)
echo "🌱 Database needs seeding..."
echo " Admin Email: $ADMIN_EMAIL"
echo " Admin Password: [HIDDEN]"
npm run db:seed
echo "✅ Seeding completed"
echo "💡 You can now login with: $ADMIN_EMAIL / $ADMIN_PASSWORD"
;;
3)
echo "🔄 Database needs migration and seeding..."
npm run db:push
echo "✅ Migration completed"
echo "🌱 Seeding database..."
echo " Admin Email: $ADMIN_EMAIL"
echo " Admin Password: [HIDDEN]"
npm run db:seed
echo "✅ Database initialization completed"
echo "💡 You can now login with: $ADMIN_EMAIL / $ADMIN_PASSWORD"
;;
4)
echo "❌ Database state check failed - see logs above"
exit 1
;;
*)
echo "❌ Unexpected database check result: $DB_CHECK_EXIT"
exit 1
;;
esac
echo "🌟 Starting server..."
# Execute the main command
exec "$@"