# Database Setup Script Write-Host "`n========================================" -ForegroundColor Cyan Write-Host " DATABASE SETUP" -ForegroundColor Cyan Write-Host "========================================`n" -ForegroundColor Cyan # Check if Docker is available if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { Write-Host "āŒ Docker not found" -ForegroundColor Red Write-Host " Please install Docker Desktop or set up PostgreSQL manually" -ForegroundColor Yellow Write-Host " See docs/DATABASE_OPTIONS.md for manual setup instructions" -ForegroundColor Gray exit 1 } Write-Host "[OK] Docker found" -ForegroundColor Green # Check if container already exists $existing = docker ps -a --filter "name=combo-postgres" --format "{{.Names}}" if ($existing) { Write-Host "`nšŸ“¦ Existing container found: $existing" -ForegroundColor Yellow # Check if running $running = docker ps --filter "name=combo-postgres" --format "{{.Names}}" if ($running) { Write-Host "[OK] Container is already running" -ForegroundColor Green } else { Write-Host "šŸ”„ Starting existing container..." -ForegroundColor Yellow docker start combo-postgres Start-Sleep -Seconds 3 } } else { Write-Host "`nšŸ“¦ Creating new PostgreSQL container..." -ForegroundColor Yellow docker run --name combo-postgres ` -e POSTGRES_PASSWORD=postgres ` -e POSTGRES_DB=comboflow ` -p 5432:5432 ` -d postgres:15 Write-Host "ā³ Waiting for database to initialize..." -ForegroundColor Yellow Start-Sleep -Seconds 5 } # Verify connection Write-Host "`nšŸ” Verifying database connection..." -ForegroundColor Yellow Start-Sleep -Seconds 3 $portCheck = Get-NetTCPConnection -LocalPort 5432 -State Listen -ErrorAction SilentlyContinue if ($portCheck) { Write-Host "[OK] PostgreSQL is running on port 5432" -ForegroundColor Green # Test connection try { $testResult = docker exec combo-postgres psql -U postgres -d comboflow -c "SELECT 1;" 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host "[OK] Database connection successful" -ForegroundColor Green } else { Write-Host "āš ļø Connection test failed" -ForegroundColor Yellow } } catch { Write-Host "āš ļø Could not test connection: $_" -ForegroundColor Yellow } } else { Write-Host "āŒ PostgreSQL is not listening on port 5432" -ForegroundColor Red Write-Host " Check container logs: docker logs combo-postgres" -ForegroundColor Gray exit 1 } Write-Host "`nšŸ“ Next steps:" -ForegroundColor Cyan Write-Host " 1. Update orchestrator/.env with:" -ForegroundColor White Write-Host " DATABASE_URL=postgresql://postgres:postgres@localhost:5432/comboflow" -ForegroundColor Gray Write-Host " RUN_MIGRATIONS=true" -ForegroundColor Gray Write-Host "`n 2. Run migrations:" -ForegroundColor White Write-Host " cd orchestrator" -ForegroundColor Gray Write-Host " npm run migrate" -ForegroundColor Gray Write-Host ""