#!/bin/bash # ============================================================ # Teressa Copeland Homes — Start Script # Run from the teressa-copeland-homes/ directory: # chmod +x start.sh (first time only) # ./start.sh # ============================================================ set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR" # ── Helpers ────────────────────────────────────────────────── GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m' info() { echo -e "${GREEN}▶ $1${NC}"; } warn() { echo -e "${YELLOW}⚠ $1${NC}"; } error() { echo -e "${RED}✗ $1${NC}"; exit 1; } # ── 1. Check prerequisites ──────────────────────────────────── command -v docker >/dev/null 2>&1 || error "Docker not found. Install Docker Desktop first." command -v docker compose >/dev/null 2>&1 || error "docker compose not found. Update Docker Desktop." # ── 2. Check .env.production exists ────────────────────────── if [ ! -f ".env.production" ]; then error ".env.production not found. Copy .env.production.example to .env.production and fill in your values." fi # ── 3. Build the app image ──────────────────────────────────── info "Building app image (this takes ~2 min on first run)..." docker compose build app # ── 4. Start everything ─────────────────────────────────────── info "Starting database and app..." docker compose up -d # ── 5. Wait for database to be healthy ─────────────────────── info "Waiting for database..." for i in $(seq 1 30); do if docker compose exec db pg_isready -U postgres -q 2>/dev/null; then break fi sleep 1 done # ── 6. Run migrations ───────────────────────────────────────── info "Running database migrations..." DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ npx drizzle-kit migrate 2>&1 | tail -3 # ── 7. Seed agent account (safe to re-run — skips if exists) ── info "Seeding agent account..." DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ AGENT_EMAIL="teressa@tcopelandhomes.com" \ AGENT_PASSWORD="AgentPortal2024!" \ npx tsx scripts/seed.ts 2>&1 | tail -3 # ── 8. Seed forms library ───────────────────────────────────── FORMS_COUNT=$(ls seeds/forms/*.pdf 2>/dev/null | wc -l | tr -d ' ') if [ "$FORMS_COUNT" -gt 0 ]; then info "Seeding $FORMS_COUNT PDF forms into library..." DATABASE_URL="postgresql://postgres:postgres@localhost:5433/teressa" \ npx tsx scripts/seed-forms.ts 2>&1 | tail -2 info "Copying forms into container..." docker compose exec app mkdir -p /app/seeds/forms 2>/dev/null || true docker cp seeds/forms/. "$(docker compose ps -q app)":/app/seeds/forms/ docker compose exec app chown -R nextjs:nodejs /app/seeds/forms/ 2>/dev/null || true else warn "No PDF forms found in seeds/forms/ — skipping forms seed." warn "See below for how to add your forms." fi # ── 9. Health check ─────────────────────────────────────────── info "Checking app health..." sleep 3 HEALTH=$(curl -s http://localhost:3001/api/health 2>/dev/null || echo "unreachable") if echo "$HEALTH" | grep -q '"ok":true'; then echo "" echo -e "${GREEN}════════════════════════════════════════${NC}" echo -e "${GREEN} ✓ App is running!${NC}" echo -e "${GREEN} Open: http://localhost:3001/agent/login${NC}" echo -e "${GREEN} Email: teressa@tcopelandhomes.com${NC}" echo -e "${GREEN} Password: AgentPortal2024!${NC}" echo -e "${GREEN}════════════════════════════════════════${NC}" echo "" else warn "Health check inconclusive (app may still be starting). Try: http://localhost:3001/api/health" fi # ── 10. Where to put forms ──────────────────────────────────── echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " 📄 ADDING PDF FORMS TO THE LIBRARY" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " Drop PDF files into:" echo " teressa-copeland-homes/seeds/forms/" echo "" echo " Then run:" echo " ./seed-forms.sh" echo " (or just re-run ./start.sh)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo ""