From 3e927fc5a8ca553529b00b188b59b39f5eb003cb Mon Sep 17 00:00:00 2001 From: Alphaeus Mote Date: Fri, 24 Oct 2025 12:18:06 -0400 Subject: [PATCH] Add master deployment script for one-command setup NEW SCRIPT: deploy.sh - Master deployment automation - Tears down existing containers and volumes - Fixes file permissions automatically - Starts fresh containers - Initializes database schema - Generates test data - Verifies deployment - IDEMPOTENT: Safe to run multiple times FEATURES: - Beautiful colored output with progress indicators - Confirmation prompt before destructive operations - Waits for PostgreSQL to be healthy before proceeding - Comprehensive access information at completion - Useful commands reference DOCUMENTATION: - Updated README.md with Option A (one-command) and Option B (manual) - Updated QUICKSTART.md with super quick start section - Manual steps now in collapsible section USER EXPERIENCE: - Clone repo + run deploy.sh = DONE - No more complex multi-step setup - Perfect for demos and quick testing - Rebuilds from scratch every time (no stale data) --- README.md | 38 +++++++- deploy.sh | 216 +++++++++++++++++++++++++++++++++++++++++++++ docs/QUICKSTART.md | 31 ++++++- 3 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 deploy.sh diff --git a/README.md b/README.md index 86b6455..aecdc78 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,38 @@ This will automatically install: --- +## 🚀 Quick Start + +### Option A: One-Command Deployment (Recommended) + +```bash +# Clone the repository +git clone https://github.com/freedbygrace/SQL.git +cd SQL + +# Deploy everything with one command +chmod +x deploy.sh +./deploy.sh +``` + +**That's it!** The master deployment script will: +1. ✅ Tear down existing containers +2. ✅ Remove old data volumes +3. ✅ Fix file permissions +4. ✅ Start fresh containers +5. ✅ Initialize database schema +6. ✅ Generate test data (15-30 minutes) +7. ✅ Verify everything works + +**IDEMPOTENT:** Safe to run multiple times - rebuilds from scratch each time. + +--- + +### Option B: Manual Step-by-Step + +
+Click to expand manual installation steps + ### 1. Clone the Repository ```bash git clone https://github.com/freedbygrace/SQL.git @@ -155,7 +187,11 @@ This starts: ⏱️ **Note:** Data generation takes 15-30 minutes depending on your system. -### 6. Access the Database +
+ +--- + +## 📊 Access the Database **Option A: pgAdmin Web Interface** ``` diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..827c39b --- /dev/null +++ b/deploy.sh @@ -0,0 +1,216 @@ +#!/bin/bash + +# ============================================================================ +# Business Analytics Database - Master Deployment Script +# ============================================================================ +# This script does EVERYTHING in one command: +# 1. Tears down existing containers +# 2. Removes all data volumes +# 3. Fixes permissions +# 4. Starts containers +# 5. Initializes database schema +# 6. Generates test data +# 7. Verifies everything works +# +# IDEMPOTENT: Safe to run multiple times - will rebuild from scratch +# ============================================================================ + +set -e # Exit on error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +MAGENTA='\033[0;35m' +NC='\033[0m' # No Color + +# Get script directory +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$SCRIPT_DIR" + +echo "" +echo -e "${MAGENTA}╔════════════════════════════════════════════════════════════════════════════╗${NC}" +echo -e "${MAGENTA}║ ║${NC}" +echo -e "${MAGENTA}║ ${CYAN}Business Analytics Database - Master Deployment${MAGENTA} ║${NC}" +echo -e "${MAGENTA}║ ║${NC}" +echo -e "${MAGENTA}╚════════════════════════════════════════════════════════════════════════════╝${NC}" +echo "" +echo -e "${YELLOW}This script will:${NC}" +echo -e " ${BLUE}1.${NC} Tear down existing containers" +echo -e " ${BLUE}2.${NC} Remove all data volumes" +echo -e " ${BLUE}3.${NC} Fix file permissions" +echo -e " ${BLUE}4.${NC} Start fresh containers" +echo -e " ${BLUE}5.${NC} Initialize database schema" +echo -e " ${BLUE}6.${NC} Generate test data" +echo -e " ${BLUE}7.${NC} Verify deployment" +echo "" +echo -e "${YELLOW}⚠️ WARNING: This will DELETE all existing data!${NC}" +echo "" +read -p "Continue? (y/N): " -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo -e "${YELLOW}Deployment cancelled.${NC}" + exit 0 +fi + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 1/7] Tearing down existing containers...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" + +if command -v docker-compose >/dev/null 2>&1; then + docker-compose down -v 2>/dev/null || true + echo -e "${GREEN}✓ Containers stopped and removed${NC}" +else + echo -e "${YELLOW}⚠ docker-compose not found, skipping...${NC}" +fi + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 2/7] Removing data volumes...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" + +if command -v docker >/dev/null 2>&1; then + # Remove named volumes + docker volume rm sql_postgres_data 2>/dev/null && echo -e "${GREEN}✓ Removed postgres_data volume${NC}" || echo -e "${YELLOW}⚠ postgres_data volume not found${NC}" + docker volume rm sql_pgadmin_data 2>/dev/null && echo -e "${GREEN}✓ Removed pgadmin_data volume${NC}" || echo -e "${YELLOW}⚠ pgadmin_data volume not found${NC}" +else + echo -e "${YELLOW}⚠ docker not found, skipping...${NC}" +fi + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 3/7] Fixing file permissions...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" + +# Make fix-permissions script executable first +chmod +x scripts/fix-permissions.sh 2>/dev/null || true + +# Run the fix-permissions script +if [ -f "scripts/fix-permissions.sh" ]; then + ./scripts/fix-permissions.sh +else + # Fallback if script doesn't exist + echo -e "${YELLOW}Running fallback permission fix...${NC}" + if command -v sudo >/dev/null 2>&1 && [ "$EUID" -ne 0 ]; then + sudo chown -R $USER:$USER . 2>/dev/null || true + fi + find . -name "*.sh" -type f -exec chmod +x {} \; 2>/dev/null || true + chmod -R 755 data/ schema/ scripts/ 2>/dev/null || true + echo -e "${GREEN}✓ Permissions fixed${NC}" +fi + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 4/7] Starting containers...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" + +docker-compose up -d + +echo "" +echo -e "${YELLOW}Waiting for PostgreSQL to be ready...${NC}" +sleep 5 + +# Wait for PostgreSQL to be healthy +MAX_WAIT=60 +WAITED=0 +while [ $WAITED -lt $MAX_WAIT ]; do + if docker exec business_analytics_db pg_isready -U data_analyst -d business_analytics >/dev/null 2>&1; then + echo -e "${GREEN}✓ PostgreSQL is ready!${NC}" + break + fi + echo -e "${YELLOW} Waiting... ($WAITED/$MAX_WAIT seconds)${NC}" + sleep 5 + WAITED=$((WAITED + 5)) +done + +if [ $WAITED -ge $MAX_WAIT ]; then + echo -e "${RED}✗ PostgreSQL failed to start within $MAX_WAIT seconds${NC}" + echo -e "${YELLOW}Check logs with: docker-compose logs postgres${NC}" + exit 1 +fi + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 5/7] Initializing database schema...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" + +./scripts/setup-database.sh + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 6/7] Generating test data...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" +echo -e "${YELLOW}⏱️ This will take 15-30 minutes depending on your system...${NC}" +echo "" + +./data/generate_data.sh + +echo "" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN}[STEP 7/7] Verifying deployment...${NC}" +echo -e "${MAGENTA}════════════════════════════════════════════════════════════════════════════${NC}" +echo "" + +./scripts/verify-setup.sh + +echo "" +echo -e "${MAGENTA}╔════════════════════════════════════════════════════════════════════════════╗${NC}" +echo -e "${MAGENTA}║ ║${NC}" +echo -e "${MAGENTA}║ ${GREEN}✓ DEPLOYMENT COMPLETE!${MAGENTA} ║${NC}" +echo -e "${MAGENTA}║ ║${NC}" +echo -e "${MAGENTA}╚════════════════════════════════════════════════════════════════════════════╝${NC}" +echo "" +echo -e "${GREEN}Your Business Analytics Database is ready!${NC}" +echo "" +echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo -e "${YELLOW}Access Information:${NC}" +echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo "" +echo -e "${BLUE}📊 pgAdmin Web Interface:${NC}" +echo -e " URL: ${GREEN}http://localhost:3000${NC}" +echo -e " Email: ${GREEN}admin@example.com${NC}" +echo -e " Password: ${GREEN}SecurePass123!${NC}" +echo "" +echo -e "${BLUE}🗄️ PostgreSQL Database:${NC}" +echo -e " Host: ${GREEN}localhost${NC}" +echo -e " Port: ${GREEN}5432${NC}" +echo -e " Database: ${GREEN}business_analytics${NC}" +echo -e " Username: ${GREEN}data_analyst${NC}" +echo -e " Password: ${GREEN}SecurePass123!${NC}" +echo "" +echo -e "${BLUE}💻 Command Line Access:${NC}" +echo -e " ${GREEN}psql -h localhost -p 5432 -U data_analyst -d business_analytics${NC}" +echo "" +echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo -e "${YELLOW}Next Steps:${NC}" +echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo "" +echo -e " ${BLUE}1.${NC} Open pgAdmin: ${GREEN}http://localhost:3000${NC}" +echo -e " ${BLUE}2.${NC} Add server connection (see credentials above)" +echo -e " ${BLUE}3.${NC} Explore the exercises: ${GREEN}./exercises/${NC}" +echo -e " - ${CYAN}01-fraud-detection/${NC} - Fraud analysis queries" +echo -e " - ${CYAN}02-customer-analytics/${NC} - Customer insights" +echo -e " - ${CYAN}03-sales-analysis/${NC} - Sales performance" +echo -e " - ${CYAN}04-kpi-dashboards/${NC} - KPI tracking" +echo "" +echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo -e "${YELLOW}Useful Commands:${NC}" +echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" +echo "" +echo -e " ${BLUE}View logs:${NC} ${GREEN}docker-compose logs -f${NC}" +echo -e " ${BLUE}Stop containers:${NC} ${GREEN}docker-compose down${NC}" +echo -e " ${BLUE}Restart:${NC} ${GREEN}docker-compose restart${NC}" +echo -e " ${BLUE}Redeploy:${NC} ${GREEN}./deploy.sh${NC}" +echo "" +echo -e "${GREEN}Happy learning! 🚀${NC}" +echo "" + diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index 0e7ac6e..cfbeb20 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -1,6 +1,35 @@ # Quick Start Guide -## 🚀 Get Up and Running in 5 Minutes +## ⚡ Super Quick Start (One Command - Recommended) + +```bash +# Clone the repository +git clone https://github.com/freedbygrace/SQL.git +cd SQL + +# Deploy everything +chmod +x deploy.sh +./deploy.sh +``` + +**Done!** The master deployment script handles everything: +- ✅ Tears down old containers +- ✅ Removes old data +- ✅ Fixes permissions +- ✅ Starts containers +- ✅ Initializes database +- ✅ Generates test data +- ✅ Verifies deployment + +**Time:** 15-30 minutes (mostly data generation) + +Skip to [Step 4: Access the Database](#step-4-access-the-database) after deployment completes. + +--- + +## 📋 Manual Step-by-Step (Alternative) + +If you prefer to run each step manually: ### Step 0: Set Proper Permissions