Files
tilbudgivern/archive/scripts/deploy-enhanced-features.sh
alexpolo1 4a372d2e28 clean up
2025-10-30 18:28:58 +00:00

255 lines
7.4 KiB
Bash
Executable File

#!/bin/bash
# Enhanced Tilbudgivern Deployment Script
# This script sets up the enhanced features for the tilbudgivern system
echo "🚀 Starting Enhanced Tilbudgivern Deployment..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if we're in the right directory
if [ ! -f "package.json" ] || [ ! -d "backend" ] || [ ! -d "frontend" ]; then
print_error "This script must be run from the tilbudgivern root directory"
exit 1
fi
print_status "Deploying Enhanced Tilbudgivern Features"
echo "========================================"
# 1. Install any new dependencies
print_status "Checking and installing dependencies..."
# Backend dependencies
if [ -d "backend" ]; then
cd backend
print_status "Installing backend dependencies..."
npm install
if [ $? -eq 0 ]; then
print_success "Backend dependencies installed"
else
print_error "Failed to install backend dependencies"
exit 1
fi
cd ..
fi
# Frontend dependencies
if [ -d "frontend" ]; then
cd frontend
print_status "Installing frontend dependencies..."
npm install
if [ $? -eq 0 ]; then
print_success "Frontend dependencies installed"
else
print_error "Failed to install frontend dependencies"
exit 1
fi
cd ..
fi
# 2. Database Schema Updates
print_status "Updating database schema for enhanced features..."
# Check if MySQL/MariaDB is running
if ! command -v mysql &> /dev/null; then
print_error "MySQL/MariaDB client not found. Please install it first."
exit 1
fi
# Load database configuration
if [ -f ".env" ]; then
source .env
else
print_warning ".env file not found, using default database settings"
export DB_HOST=${DB_HOST:-localhost}
export DB_USER=${DB_USER:-tilbuduser}
export DB_PASSWORD=${DB_PASSWORD:-tilbudpass123}
export DB_NAME=${DB_NAME:-tilbudgivern}
export DB_PORT=${DB_PORT:-3306}
fi
print_status "Database: $DB_NAME on $DB_HOST:$DB_PORT"
# Test database connection
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASSWORD" -e "USE $DB_NAME;" 2>/dev/null
if [ $? -eq 0 ]; then
print_success "Database connection successful"
else
print_error "Cannot connect to database. Please check your database configuration."
print_status "You may need to:"
print_status "1. Start your database server"
print_status "2. Check your .env file database settings"
print_status "3. Ensure the database and user exist"
exit 1
fi
# Apply database schema updates
print_status "Applying enhanced features schema updates..."
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" < setup_enhanced_features.sql
if [ $? -eq 0 ]; then
print_success "Database schema updated successfully"
else
print_error "Failed to update database schema"
exit 1
fi
# 3. Build Frontend if needed
print_status "Building frontend for production..."
cd frontend
npm run build
if [ $? -eq 0 ]; then
print_success "Frontend built successfully"
else
print_error "Failed to build frontend"
exit 1
fi
cd ..
# 4. Copy build to main build directory
if [ -d "frontend/build" ]; then
print_status "Copying frontend build to main build directory..."
cp -r frontend/build/* build/ 2>/dev/null || mkdir -p build && cp -r frontend/build/* build/
print_success "Frontend build copied"
fi
# 5. Verify enhanced services are accessible
print_status "Verifying enhanced services..."
# Check if enhanced services files exist
services_check=true
if [ ! -f "backend/src/services/packageService.js" ]; then
print_error "Package service not found"
services_check=false
fi
if [ ! -f "backend/src/services/advancedGeometryService.js" ]; then
print_error "Advanced geometry service not found"
services_check=false
fi
if [ ! -f "backend/src/services/timeCalculatorService.js" ]; then
print_error "Time calculator service not found"
services_check=false
fi
if [ ! -f "backend/src/routes/enhancedFeatures.js" ]; then
print_error "Enhanced features routes not found"
services_check=false
fi
if [ ! -f "frontend/src/components/EnhancedTilbudgivern.js" ]; then
print_error "Enhanced frontend component not found"
services_check=false
fi
if [ "$services_check" = true ]; then
print_success "All enhanced service files found"
else
print_error "Some enhanced service files are missing"
exit 1
fi
# 6. Test basic functionality
print_status "Testing enhanced features integration..."
# Start the server in background for testing
print_status "Starting server for integration test..."
timeout 10s node unified-server.js &
server_pid=$!
sleep 5
# Test if server started
if ps -p $server_pid > /dev/null 2>&1; then
print_success "Server started successfully"
# Test enhanced API endpoint
if command -v curl &> /dev/null; then
curl -s "http://localhost:4031/api/enhanced/packages/Betontegl" > /dev/null
if [ $? -eq 0 ]; then
print_success "Enhanced API endpoints accessible"
else
print_warning "Enhanced API endpoints may need manual verification"
fi
fi
# Clean up test server
kill $server_pid 2>/dev/null
else
print_warning "Server test skipped - may need manual verification"
fi
# 7. Final verification and summary
print_status "Running final verification..."
echo ""
echo "========================================"
print_success "Enhanced Tilbudgivern Deployment Complete!"
echo "========================================"
echo ""
print_status "🎯 Enhanced Features Deployed:"
echo " ✅ Package Management System"
echo " ✅ Advanced Geometry Calculations"
echo " ✅ Team-Scaled Time Calculator"
echo " ✅ Integrated API Routes"
echo " ✅ Enhanced Frontend Components"
echo " ✅ Database Schema Updates"
echo ""
print_status "🚀 Next Steps:"
echo " 1. Start the server: npm start or node unified-server.js"
echo " 2. Access the enhanced interface at: http://localhost:4031"
echo " 3. Test the new features in the interface"
echo " 4. Check logs for any issues: tail -f backend/combined.log"
echo ""
print_status "📁 Key Files Updated:"
echo " • Database: setup_enhanced_features.sql applied"
echo " • Backend: Enhanced services and API routes added"
echo " • Frontend: EnhancedTilbudgivern component available"
echo " • Server: unified-server.js updated with new routes"
echo ""
print_status "🔧 Configuration:"
echo " • Database: $DB_NAME on $DB_HOST:$DB_PORT"
echo " • Server Port: ${PORT:-4031}"
echo " • Environment: ${NODE_ENV:-development}"
echo ""
# Check if PM2 is available for production deployment
if command -v pm2 &> /dev/null; then
print_status "💡 Production Tip:"
echo " Use PM2 for production deployment:"
echo " pm2 start ecosystem.config.json"
else
print_status "💡 Production Tip:"
echo " Consider installing PM2 for production deployment:"
echo " npm install -g pm2"
fi
print_success "Deployment completed successfully! 🎉"
echo ""
print_status "Testing the enhanced features now..."
echo "Open your browser and navigate to: http://localhost:4031"
echo ""